system
November 27, 2010, 7:40am
1
Is there any easy way to set up multiple conditions for a function to be called?
The only way I have been able to rig was this: (any cleaner way)?
function Update () {
if( Input.GetButtonDown( "Fire1" ) )
{if (Bomb >= 1){
Instantiate(particlePrefab, transform.position, transform.rotation);
Bomb-=1;}}
}
duck
November 27, 2010, 8:09am
2
Yes, you can use the "Or" and "And" operators, which are || and &&. For example, the above situation can be implemented using "And" (&&). In this situation, *both conditions must be true for the enclosed code to get executed:
if ( Input.GetButtonDown( "Fire1" ) && bomb > 0 ) {
Instantiate(particlePrefab, transform.position, transform.rotation);
bomb -= 1;
}
You would use "Or" (||) in situations where you want your code to execute in the case of either condition being true, for example:
if ( collider.tag == "Spikes" || collider.tag == "Lava" ) {
KillPlayer();
}