I build a simple mine:
The player (Object with the tag player) collides an it goes off, dealing some dammage
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.
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
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)
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.