1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-22 07:08:51 -05:00
UDRIGEEKCup2024/Assets/MoveFloor.cs

36 lines
943 B
C#
Raw Permalink Normal View History

2024-04-22 14:43:40 -04:00
using Unity.Mathematics;
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]
[SerializeField] private Vector3 direction = Vector3.right;
private Vector3 startPos;
private void Start()
{
startPos = transform.position;
}
2024-04-22 14:43:40 -04:00
private void Update()
{
if (Vector3.Distance(startPos, transform.position) > distance || Vector3.Distance(startPos, transform.position) < -distance)
{
direction *= -1;
}
2024-04-22 14:43:40 -04:00
var speedScaled = speed * Time.deltaTime;
transform.Translate(direction.normalized * speedScaled, Space.Self);
}
}
}