2024-04-22 14:43:40 -04:00
|
|
|
using Unity.Mathematics;
|
2024-04-22 09:47:46 -04:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace MAVRIC.GEEKCup
|
|
|
|
{
|
|
|
|
public class MoveFloor : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Range(0f, 10f)]
|
|
|
|
[SerializeField] private float speed = 1f;
|
|
|
|
|
|
|
|
[Range(0f, 10f)]
|
|
|
|
[SerializeField] private float distance = 1f;
|
|
|
|
|
2024-04-22 14:43:40 -04:00
|
|
|
[PostNormalize]
|
2024-04-22 09:47:46 -04:00
|
|
|
[SerializeField] private Vector3 direction = Vector3.right;
|
|
|
|
|
|
|
|
private Vector3 startPos;
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
startPos = transform.position;
|
|
|
|
}
|
2024-04-22 14:43:40 -04:00
|
|
|
|
2024-04-22 09:47:46 -04:00
|
|
|
private void Update()
|
|
|
|
{
|
2024-04-22 15:32:35 -04:00
|
|
|
if (Vector3.Distance(startPos, transform.position) > distance || Vector3.Distance(startPos, transform.position) < -distance)
|
2024-04-22 09:47:46 -04:00
|
|
|
{
|
|
|
|
direction *= -1;
|
|
|
|
}
|
2024-04-22 14:43:40 -04:00
|
|
|
|
|
|
|
var speedScaled = speed * Time.deltaTime;
|
|
|
|
|
|
|
|
transform.Translate(direction.normalized * speedScaled, Space.Self);
|
2024-04-22 09:47:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|