- Home /
My script doesn work Trigger Problem!! HELP!!
tell me what in my script is not good...beause the trigger doens work...
var Detect=false;
var AnyTag=false;
function Update () {}
function OnTriggerStay(Hit:Collider)
{
if(Hit.gameObject&&AnyTag){Detect=true;}
if(Hit.gameObject.tag=="terrain"){Detect=true;}
}
function OnTriggerExit(){Detect=false;}
What part of your script doesn't work? Does it compile? If so, what behaviour are you seeing that seems wrong? Have you attempted to put a break point in the problem code to see if it is being called and then check what code paths are being executed?
Answer by magnussolidus · Nov 05, 2012 at 01:13 PM
Did you guys forget that you need to have a rigid body attached to one of the game objects that are colliding to activate the trigger? Check if this isn't the problem! I forget the link to the collision matrix, but try to find something about triggers collision on documentation and you will know about what I'm talking about.
Note: Will be better apply the rigid body to the game object that is moving, not the static one. Please check the documentation for further information.
Hope it helps =)
because...i used an other sript that have the same function but different gameobject...and those gameobject are rigidbody but not the transform and its working...so if i do understand...that mean the transform need to be a rigidbody or the target need to be riight? thats my analyse thesis?
YO...YO..Yo dawg!!! for real...u saved my life...you just make me understand something that can solve my other problems that i had no answers....so yo for real THAN$$anonymous$$S YOU!!...Yo bro i guest u cant understand...but got dam son....i gotta thanks u again!!
Answer by Montraydavis · Nov 04, 2012 at 07:53 PM
Why is the AnyTag in the if ? Is that meant to be there because I see no other references . . . O.o
Try this:
var Detect : boolean = false ;
function Update ( ){
}
function OnTriggerStay ( collision : Collider )
{
if ( collider.gameObject.tag == "terrain" )
{
Detect = true ;
}
}
function OnTriggerExit ( collision : Collider )
{
if ( collider.gameObject.tag == "terrain" )
{
Detect = false ;
}
}
Do you have Rigidbodies and Box Colliders enabled? And what do you mean "still not working" . I still don't understand "what doesn't work" . . . Are you falling through the floor ? Walking through walls? Partially falling through floor? etc?
Answer by magnussolidus · Nov 06, 2012 at 12:04 AM
At least one of the game objects need to have a rigid body component attached to it if you wanna Unity to detect the trigger.
Please, take a loot at this: http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
In the end you have the collision matrix. =)
Can you post the code so I can take a look of it and try to find the problem?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
My script doesnt respond what i wrote HELP!!! 0 Answers
Message sender...how to know who send the message 1 Answer
Array Help GameObject Length Inventory 1 Answer
Unity3D Timer. 1 Answer