mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 07:08:51 -05:00
36 lines
943 B
C#
36 lines
943 B
C#
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;
|
|
|
|
[PostNormalize]
|
|
[SerializeField] private Vector3 direction = Vector3.right;
|
|
|
|
private Vector3 startPos;
|
|
|
|
private void Start()
|
|
{
|
|
startPos = transform.position;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Vector3.Distance(startPos, transform.position) > distance || Vector3.Distance(startPos, transform.position) < -distance)
|
|
{
|
|
direction *= -1;
|
|
}
|
|
|
|
var speedScaled = speed * Time.deltaTime;
|
|
|
|
transform.Translate(direction.normalized * speedScaled, Space.Self);
|
|
}
|
|
}
|
|
} |