- Home /
Collision wont be detected
I have a Child named Waypoint of the game object player and the other child PlayerObj moves towards Waypoint. The Enemy has a mesh on it with the renderer turned off and the trigger turned on(the script attached to it is below). The problem is when the PlayerObj collides with the mesh on the enemy it doesn't recognize it, any idea why would be very helpful.
var Target : String;
function OnTriggerEnter (Enter : Collider)
{
if (Enter.gameObject.tag == "Player")
{
Debug.Log("Colided");
var contact : String = Enter.transform.name;
Target = contact;
transform.root.gameObject.SendMessage ("AttackingOn");
transform.root.gameObject.SendMessage ("TargetNumber", Target);
}
}
1st thing that comes to my $$anonymous$$d is if all the objects have colliders.
after that check ur code without the condition if. if it works try placing the condition agian, and make sure ur tag is correct.
try to print something inside the if to see it it works like print(1); this will make the console print 1 if the condition works.
gl
Answer by ScroodgeM · Jul 24, 2012 at 10:40 PM
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html
Note that collision events are only sent if one of the colliders also has a non-kinematic rigid body attached.
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html
Note that trigger events are only sent if one of the colliders also has a rigid body attached.