N
N
Nikola_y2015-01-31 23:02:17
C++ / C#
Nikola_y, 2015-01-31 23:02:17

How to do object selection in Unity3d?

void OnTriggerStay(Collider col){
    if (col.gameObject.tag == "mob") 

    {
      GameObject target = GameObject.FindGameObjectWithTag ("mob");
      transform.LookAt(target.transform);
      }	
}

How to make it so that when the object exits the Trigger, the object starts looking for a new target
And does not look at the old
one If through OnTriigerExit
Then how to initialize an object that is already in target
So that when exiting Target = null;
And not when any object exits the Trigger
Thank you

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Romanov, 2015-01-31
@Djaler

OnTriggerExit2D?

E
Espleth, 2015-01-31
@Espleth

There are also functions OnTriggerEnter and OnTriggerExit if I made a mistake with the names. The second is what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question