MiniGames/Assets/Scripts/SkyWalker/Skywalker_MovingPlatform.cs

26 lines
574 B
C#
Raw Permalink Normal View History

2025-09-01 00:01:33 +05:00
using UnityEngine;
public class Skywalker_MovingPlatform : MonoBehaviour
{
public float speed = 2f;
public float distance = 3f;
private Vector3 startPos;
2025-09-06 23:30:06 +05:00
public bool reverse;
2025-09-01 00:01:33 +05:00
void Start()
{
startPos = transform.position;
}
void Update()
{
2025-09-06 23:30:06 +05:00
if (!reverse)
2025-09-01 00:01:33 +05:00
{
2025-09-06 23:30:06 +05:00
transform.position = startPos + Vector3.down * Mathf.PingPong(Time.time * speed, distance);
2025-09-01 00:01:33 +05:00
}
2025-09-06 23:30:06 +05:00
else
2025-09-01 00:01:33 +05:00
{
2025-09-06 23:30:06 +05:00
transform.position = startPos + Vector3.up * Mathf.PingPong(Time.time * speed, distance);
2025-09-01 00:01:33 +05:00
}
2025-09-06 23:30:06 +05:00
2025-09-01 00:01:33 +05:00
}
}