- Home /
turning a game object on trigger (Javascript)
so, what I'm trying to do is make it so when the Box Collider (as trigger) that is tagged "vision" moves over the trigger on a doll, the doll will not rotate, but when it's off, the doll will turn with LookAt and look at the player.. So long as they're watching it, it won't move at all.
So far, it will only start looking at the player after the tagged player object, itself, enters the trigger area (which is too close to be of use for a horror game), and then it won't turn off at all.. What am I doing wrong?
This is the script I have..
#pragma strict
var target : Transform;
var looking = true;
function Start () {
target = GameObject.FindWithTag("Player").transform;
}
function OnTriggerEnter(other:Collider) {
if(other.gameObject.tag=="vision")
{
looking = true;
}
else
{
looking = false;
}
}
function Update () {
if(looking == false)
{
transform.LookAt(target);
}
}
thanks in advance!
There are more than one trigger functions. You may want to use OnTriggerExit to reset your values.
Answer by revolute · Oct 14, 2014 at 06:01 AM
You have to remember that OnTriggerEnter is called only once. If you want to know if it is inside, and want it to keep triggering, use OnTriggerStay.
I'll try this when I get home.. I don't know why I didn't think about that.. I'll try that for getting it to move, but that doesn't fix the problem of the trigger not registering the game object "vision" when it's supposed to.. (reacts to "player" tag but not "vision" tag)
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Iphone Unity and Best book . 1 Answer
Play Animation on trigger enter 1 Answer
C# to UnityScript conversion help. 0 Answers