- Home /
Trigger and Collider Issues
I know that there are certain formulas for colliders as in some work with others and some don't. I have checked the unity physics page ie: Link. I need some clarification on the combinations for a project.
I have a very simple script here, but OnTriggerEnter is never returning true. I believe this is due to an invalid combination of triggers/colliders. The script is attached to a movable gameobject, which has a BoxCollider and a SphereCollider set to "isTrigger". On the other gameobject i have a BoxCollider. None of them have Rigidbodys. Any help on why OnTriggerEnter is never returning?
Some Code:
function OnTriggerEnter(trig:Collider){
if(trig.tag == "Building"){
Debug.Log("Building");
building = trig.transform.parent.gameObject;
buidlingScript = building.GetComponent(Building);
build = true;
}
}
Answer by code-blep · Nov 18, 2012 at 01:00 AM
You need at least one rigidbody attached. I just tested your code and the only thing missing is a rigidbody on one of the gameobjects. When applied it works.
It is stated here if you want to read up on it:
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html
Hope it helps landon91235 :)
Wait, before you answer that, I'm having an error. I know this is a really old post, but well. It says that "tag" isn't a member of "UnityEngine.Collision".