Hi there,
I’m currently working on a little game wich requires me to have collision between a gameobject and the terrain the game plays on.
This is the script I came up with:
void OnTriggerEnter(Collision other)
{
if(other.gameObject.name == "Terrain")
{
Debug.Log("hit");
}
}
For some reason this does nothing so I tried letting it collide with other object, those don’t do anything either.
Any help would be greatly apreciated!
Thanks!
Does the gameobject have a rigidbody? Unity docs say that collision events are only called when one of the colliders has a rigidbody attached.
sath
January 8, 2014, 10:10pm
4
Check your terrain gameObject name in your Hierarchy. Is it “Terrain” or “terrain” ?
Check the spelling so it can much with the name “Terrain” in your script
Does the terrain collider have Is Trigger checked? If not (and I suspect it doesn’t), you should be using OnCollisionEnter(), not OnTriggerEnter().
void OnTriggerEnter(Collision other) {
is wrong … it’s supposed to be
void OnTriggerEnter(Collider other) {