As title says killing all enemies with tag enemy , all in Java
Fly (enemy) Collision Code:
#pragma strict
function OnCollisionEnter2D(collision2D: Collision2D ){
var gameManager = GameObject.FindGameObjectWithTag("GameController");
//var player = GameObject.FindGameObjectWithTag("Player");
//var fly = GameObject.FindGameObjectWithTag("Fly");
if (collision2D.gameObject.tag == "Player"){
gameManager.SendMessage ("DeathFly");
}
}
GameManager code : (only the parts for the enemies as its a long script)
#pragma strict
var fly : GameObject;
function DeathFly(){
fly = GameObject.FindGameObjectWithTag("Enemy");
fly.SendMessage("Kill");
}
Fly (enemy) Code :
#pragma strict
var damage : int = 10;
var health : int = 10;
var hitSound : AudioClip;
var flySound : AudioClip;
var deathSound : AudioClip;
var Boost : GameObject;
var healthBar : UI.Slider;
function Update(){
var audio : AudioSource = GetComponent.<AudioSource>();
if(health == 0){
AudioSource.PlayClipAtPoint(deathSound, Camera.main.transform.position);
Kill();
}
healthBar.value = health;
}
function Kill(){
Boost = Instantiate(Resources.Load("Prefabs/Cloud"), transform.position, transform.rotation) as GameObject;
Destroy(this.gameObject);
}
function ApplyDamage(){
health = health -= damage;
}
if anyone could help with killing when landing on the head i would be very great full.