I’ve been through numerous related answers on here but just can’t get my collisions working properly.
I’ve have a prefab gameobject called Bullet with the following script attached. The bullets are physically colliding with another prefab game object which has the tag “asteroid”. However I am now adding a scoring system and need the score to change when the two objects collide. Both have a rigid body and a sphere collider attached. Neither is isTrigger or kinematic. But I can’t get the debug to work when they collide.
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Asteroid")
{
Debug.Log("hit");
}
}
I would check that the Tag you assigned the object is exactly the same including capitalization,I cant help noticing in your question it is not, if not that can you post a pic of your setup with the onbjects Selected?
Make sure the tag you are referring to is spelled exactly the same in your script.
You can also try this if ^ doesnt work try this: (make sure to enable the isTrigger option for either of the objects)
void OnTriggerEnter(collider other)
{
if (other.gameObject.name == [the object name here] )
{
Debug.Log("Object has been hit!")
}
}
Thanks for your help, both the bullet and the asteroids were prefabs and I hadn’t used the tag on the prefab, just on the objects in hierarchy.
Working now!