I build a simple mine: The player (Object with the tag player) collides an it goes off, dealing some dammage Code (csharp): var sound : AudioClip; var soundVolume : float = 2.0; var explosion : Transform; var spawn : Transform; function OnTriggerEnter(other:Collider) { if (other.tag != "Player") return; // return beendet hier die Funktion fals das Tag nicht Player if (sound) // ansonsten gehts hier weiter AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume); Destroy(gameObject); if (explosion) Instantiate (explosion, transform.position, transform.rotation); if (spawn) Instantiate (spawn, transform.position, transform.rotation); } It plays a soundfile, kills itself, spawns some debris and an explosion which does the damage One problem is: now it uses it's collider as trigger but i want it to be a riggidbody to be able to bounce of the floor. And at the moment you can't shoot it. It deals but does not receive dammage.
Simply change: function OnTriggerEnter(other:Collider) to function OnCollisionEnter(other:Collider) ...then you can use it as any rigid body.
thanks alot. It makes sense to me that it should react to a collision and not via a trigger. But now how do i make it distinguish to which tag it reacts. Before i made it blow only with player tagged objects Code (csharp): function OnCollisionEnter(collision : Collision) { if (collision.tag != "Player") return; This part does not work anymore: if (collision.tag != "Player")
I did look at the fps tutorial and came up wit a not very graceful solution: I use 2 parts the Mine and the Trigger The Mine is a RiggidBody Code (csharp): var explosion : Transform; var spawn : Transform; function BlowUp () { print ("BOOOM!!!"); Destroy(gameObject); if (explosion) Instantiate (explosion, transform.position, transform.rotation); if (spawn) Instantiate (spawn, transform.position, transform.rotation); } The red part on top is the trigger it's collider is set to trigger ( seems they should not touch each other) Code (csharp): var sound : AudioClip; var soundVolume : float = 2.0; var target : Transform; function OnTriggerEnter(other:Collider) { if (other.tag != "Player") return; // return beendet hier die Funktion fals das Tag nicht Player if (sound) AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume); print ("BUM"); if (target.GetComponent("MineV2") != null) target.GetComponent("MineV2").BlowUp(); } feel like a workarount to me but does the job But i am always interested in better solutions. :wink: