So i would need to check if an object is something or somethingElse.
function OnTriggerEnter(object : Collider)
{
if(object.name != "Test's Laser Turret1" || "Test's Laser Turret2" || "Test's Laser Turret3" || "Test's Laser Turret4" || "Test's Laser Turret5" || "Test's Laser Turret6" || "Test's Laser Turret7" || "Test's Laser Turret8")
{
Instantiate(explosion, transform.position, transform.rotation);
Destroy(gameObject);
}
}
You have your answer in your question :
it is either something or somethingElse. So why not just declaring some properties in your TurretClass like :
public isFriendly = false; //it's is either friendly or not
public typeDescription = "Turret";
Then in you GameObject Class (presumably a projectile i am guessing) making the method as :
function OnTriggerEnter(object:Collider) {
if(object.isFriendly == false && object.typeDescription =="Turret")
{
//Do something with your gameObject
}
}
The problem here is:
if(object.name != "Test's Laser Turret1" || "Test's Laser Turret2"
This is not how the operators work, you would write it like this:
if(object.name != "Test's Laser Turret1" || object.name != "Test's Laser Turret2" || object.name != "
et.c.
Even more, in this case you actually want && (AND) instead of || (OR), otherwise it will check if the object.name is not Test’s Laser Turret1 and because this is true it will execute your code because it doesnt require the other ones to also be true (which is what && (“and also”) would fix).
So what you really want here is:
if(object.name != "Test's Laser Turret1" && object.name != "Test's Laser Turret2" && object.name != "
But of course when you become a serious programmer and you see repetitive patterns like these what you want to do is make functionality that will handle the small difference for you or exploit what the Turrets have in common with eachother, just like @AlwaysSunny and @Mathieu_Dossmann posted.