Specific object collision

Hi all, I have set up a collision script so that one a specific game object "missile" collides with another game object "roid" a particle is instantiated at the "roids" position. For some reason no matter what object collides with the roid the particle is instantiated. How can I get the particle to fire ONLY if the objects colliding are the "missile" and the "roid"? Here is the code I am using for this:

var roid: Rigidbody;
var missile: Rigidbody;
var missileExplodeFire: ParticleEmitter;
var missileExplodeFireRed: ParticleEmitter;
var missileExplodeRock: ParticleEmitter;

function OnCollisionEnter (collision : Collision) {

    if (collision.gameObject.missile == collision.gameObject.roid)
    {
        missileExplodeFire = Instantiate(missileExplodeFire, roid.position, transform.rotation);
        missileExplodeFireRed = Instantiate(missileExplodeFireRed, roid.position, transform.rotation);
        missileExplodeRock = Instantiate(missileExplodeRock, roid.position, transform.rotation);
        missileExplodeFire.emit = true;
        missileExplodeFireRed.emit = true;
        missileExplodeRock.emit = true;
    }
    if (!collision.gameObject.missile == !collision.gameObject.roid)
    {

    }
}

Any ideas would be greatly appreciated.

1 Answer

1

Hi all, Solved this problem by creating with tags rather than simply trying to reference the rigidbody variables missile and roid in the OnCollisionEnter function.