There is a tower game object and a watcher trigger. Upon entering the watcher game target object, the tower turns toward the object that entered the trigger.
Now I use trasform.lookAt and everything suits me, but the question is, if we say I want to add a tower to the rotationSpeed that directly affects the speed of rotation, which method or algorithm should I use?
Now the code is:
public class Watching : MonoBehaviour { public List<GameObject> targets; /* список объектов, которые вошли в триггер */ public GameObject controledObject; /* tower */ void OnTriggerEnter(Collider target) { targets.Add(target.gameObject); } void OnTriggerExit(Collider target) { targets.Remove(target.gameObject); } void Update () { if(this.targets.Count > 0) { GameObject target = this.targets[0]; controledObject.transform.LookAt(target.transform); } } }
this.herethis., you are welcome. - CGLikethisrefers to the current instance of the class and gives access to thetargetsfield - ThisManOnTriggerEnter(Exit)the scope allows you to gettargetswithoutthis.- CGLike