unity 3d student

Beginner B20 – IF Statements and Booleans

How to use IF / ELSE statements to check the status of variables and booleans to act as a switch.

Code Used (Javascript)

var myCheck : boolean = true;
  1.  
  2. function Update () {
  3.  
  4.  if(myCheck){
  5.   guiText.text = "Its on!";
  6.  }else{
  7.   guiText.text = "Its Off!";
  8.  }
  9.  
  10.  if(Input.GetButtonUp("Jump") && myCheck){
  11.   myCheck = false;
  12.  }else if(Input.GetButtonUp("Jump") && myCheck == false){
  13.   myCheck = true;
  14.  }
  15. }

Further Reading

Share via Social Media

  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites

23 Comments