- Home /
Multiple function conditions?
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;}}
}
Comment
Best Answer
Answer by duck · Nov 27, 2010 at 08:09 AM
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();
}
Your answer
Follow this Question
Related Questions
random range/if conditions? 2 Answers
"tag" & "if condition with OnTriggerEnter 2 Answers
Wearied Error 1 Answer
Script block animations and other scripts 2 Answers
GameObject tag to if condition 1 Answer