using System.Collections; using System.Collections.Generic; using UnityEngine; public class Move : MonoBehaviour { public Vector3 direction; public float distance = 1f; float speed = 1; Vector3 startPos; void Start() { startPos = transform.position; } void FixedUpdate() { if (transform.position.x > startPos.x + distance || transform.position.x < startPos.x - distance) { speed = -speed; } else if (transform.position.y > startPos.y + distance || transform.position.y < startPos.y - distance) { speed = -speed; } else if (transform.position.z > startPos.z + distance || transform.position.z < startPos.z - distance) { speed = -speed; } transform.Translate(direction * 0.02f * speed); } }