Jaysta
February 17, 2014, 2:43am
1
void OnTriggerEnter(Collider other){
if(other.gameObject.tag == "Ground Enemy"){
VehicleHealthEnemyCS enemyHealth = other.GetComponent<VehicleHealthEnemyCS>();
enemyHealth.TakeDamage(myDamageAmount);
if(!despawned)
Explode();
return;
}else if(other.gameObject.tag == "Air Enemy"){
AirHealthCS enemyAirHealth = other.GetComponent<AirHealthCS>();
enemyAirHealth .TakeDamage(myDamageAmount);
if(!despawned)
Explode();
return;
}else if(other.gameObject.tag == "Base Enemy"){
AllEnemyBaseHealthCS enemyBaseHealth = other.GetComponent<AllEnemyBaseHealthCS>();
enemyBaseHealth.TakeDamage(myDamageAmount);
if(!despawned)
Explode();
return;
}else if(other.gameObject.tag == "Ground"){
if(!despawned)
Explode();
return;
}
}
void OnTriggerEnter(Collider other){
if(other.gameObject.tag == "Air Enemy" || other.gameObject.tag == "Ground Enemy" || other.gameObject.tag == "Base Enemy" || other.gameObject.tag == "Ground"){
other.gameObject.SendMessage("TakeDamage", myDamageAmount, SendMessageOptions.DontRequireReceiver);
if(!despawned)
Explode();
}
}
1: As you’ve already written the code anyway, why would you not just try both and find out for yourself?
It’s irrelevant anyway, unless you have a bucketload of things entering triggers all the time. It’s a one off check. You really only need to worry about the performance of code for stuff that happens many times per frame.