I know this is asked often, but I have read pretty much every bit of information on this that I can find, all other Q&As, the resources page etc. and can’t figure this out.
I have an object, SoundSphere, which when it collides with another object should destroy itself, as opposed to the other object.
I’m attempting to use this code, which I modified to fit my project from another Q&A, and is attached to my SoundSphere:
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == "MonolithicShard")
{
// if the hit object's name is MonolithicShard...
Destroy(collision.gameObject); // destroy it
}
}
A rigidbody is attached to the SoundSphere, with a sphere collider. The MonolithicShards are tagged as such, and feature mesh colliders which are triggers.
When the SoundSpheres hit the shards they trigger a colour change in the shard, this particular script is attached to the shard. So that aspect of the collision works. I figured I could have the shard destroy the sphere, but I can’t seem to get that to work either, as I can’t figure out how to destroy the particular sphere that has triggered the colour change code.
Sorry for posting yet another question about this topic, but I just can’t solve it. Hope I’ve provided enough information.
Cheers
Nate