using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class doormove : MonoBehaviour { float distance1 = 0; bool right1 = true; void Update() { float dx = 0; if (right1 == true) { dx = 5 * Time.deltaTime; distance1 += dx; if (distance1 >= 10) { right1 = false; distance1 = 0; } } else if (right1 == false) { dx = -5 * Time.deltaTime; distance1 += dx; if (distance1 <= -10) { right1 = true; distance1 = 0; } } this.transform.Translate(dx, 0, 0, Space.Self); } }