- Home /
get object with tag for LookAt();
function OnTriggerEnter (enter : Collider)
{
if(enter.gameObject.tag == "Enemy")
{
transform.LookAt();
}
}
I'd like to get the thing that tripped the OnTriggerEnter to be the target for the LookAt();
Answer by · Sep 03, 2010 at 11:15 AM
Try:
function OnTriggerEnter (enter : Collider)
{
if (enter.gameObject.tag == "Enemy")
{
transform.LookAt(enter.transform.position);
}
}
Dude its me jason and i cant comment on my account so im getting a friend to, your script doesnt work, it has no errors but doesnt do what its supposed to? Any other idea on how to do some thing like this or even a way tto refine your script to allow it to work?
What exactly do you want looking at the enemy? This should orient the Collider (trigger) to look at the enemy. If that's not what you're after, please update your question to say so and I'll fix up the script.
The LookAt function only happens once. If you're expecting it to follow the thing that entered it, you'll have to declare the transform as a variable, set it in the onTriggerEnter, then use LookAt in an update cycle.
Answer by Black Widow 1 · Dec 02, 2010 at 02:29 AM
Adam,
Your comments - above - set it in the onTriggerEnter, then use LookAt in an update cycle.
Can you give me an example as i am rather new and not sure how to do this.
I would like to mouse down to taret/LookAt/shoot but when i mouse down elswhere i want the taret/LookAt to stop untill i click on the target again.
Thanks
Your answer
Follow this Question
Related Questions
Multiple Colliders Trigger problem 2 Answers
Unity crashes after I destroy a gameobject 1 Answer
Destructible GameObject OnTriggerEnter2D getting called twice 1 Answer
Mission Objectives 1 Answer