using System.Collections; using System.Collections.Generic; using UnityEngine; public class doormove : MonoBehaviour { // Start is called before the first frame update void Start() { } float distance1 = 0; bool right1 = true; // Update is called once per frame 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); //this.transform.Translate(0, dx, 0, Space.Self); } }