1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-22 15:18:25 -05:00
UDRIGEEKCup2024/Assets/Moving.cs

33 lines
904 B
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
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;
[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;
}
transform.Translate((direction * 0.5f) * (speed * Time.deltaTime), Space.Self);
}
}
}