using System.Collections; using System.Collections.Generic; using UnityEngine; public class RotateObject : MonoBehaviour { public float rotateSpeed = 5f; public bool rotateAlways = true; public Vector3 rotateDir = Vector3.up; bool enableRotate; // Start is called before the first frame update void OnTriggerEnter(Collider other) { enableRotate = true; } // Start is called before the first frame update void OnTriggerExit(Collider other) { enableRotate = false; } // Update is called once per frame void Update() { if ( rotateAlways || enableRotate) { transform.Rotate(rotateDir * Time.deltaTime * rotateSpeed); } } }