- Home /
change between two values (If /Else)
Hi probably a really obvious answer to this one but I cannot seem to crack it lol,I thought I was doing soo well hehe,anyway im trying to change control method on a driving game (for tablet) so when i press a button on screen the steering switches from rotate tablet to on screen joysticks ,I can make both ways work perfectly BUT and heres the stupid part lol I cannot change betteen them in game lol , I comment out the line i dont want ,see code below and please point out the obvious to me lol :)
 var con : float;
     function OnGUI() {
         
         if (!btnTexture) {
             Debug.LogError("Please assign a texture on the inspector");
               }
         if (GUI.Button(Rect(400,200,50,50),btnTexture))
                Application.LoadLevel(1);
            //Debug.Log("Clicked the button with an image");
     
     } 
 
    //   Previous button code works :)
 
     con = 1;
     function GetInput(){
        if con=1;
      steer = -Input.acceleration.y*2;  // hide this line or the line below
  throttle = Mathf.Clamp(Input.GetAxis("Vertical") + rightjs.position.y, -1 , 1);
     booster = Mathf.Clamp(Input.GetAxis("Vertical") + leftjs.position.y, 0 , 1);
 else;
      steer = Mathf.Clamp(Input.GetAxis("Horizontal") + leftjs.position.x, -1, 1);
      throttle = Mathf.Clamp(Input.GetAxis("Vertical") + rightjs.position.y, -1 , 1);
     booster = Mathf.Clamp(Input.GetAxis("Vertical") + leftjs.position.y, 0 , 1);
     }
I cannot seem to use ELSE IF command to pick one or the other lol
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by javanoob · Nov 17, 2012 at 01:05 AM
 var con : float;
     function OnGUI() {
 
         if (!btnTexture) {
             Debug.LogError("Please assign a texture on the inspector");
               }
         if (GUI.Button(Rect(400,200,50,50),btnTexture))
                con = 2;
            
            //Debug.Log("Clicked the button with an image");
        }     
 
        // con = 1;
     function GetInput(){
        if(con==2){
           steer = -Input.acceleration.y*2;  
           throttle = Mathf.Clamp(Input.GetAxis("Vertical") + rightjs.position.y, -1 , 1);
           booster = Mathf.Clamp(Input.GetAxis("Vertical") + leftjs.position.y, 0 , 1);
        }else{
           steer = Mathf.Clamp(Input.GetAxis("Horizontal") + leftjs.position.x, -1, 1);
           throttle = Mathf.Clamp(Input.GetAxis("Vertical") + rightjs.position.y, -1 , 1);
           booster = Mathf.Clamp(Input.GetAxis("Vertical") + leftjs.position.y, 0 , 1);
     }
 }
Thanks dude :) this works you got it :)
Answer by programmrzinc · Nov 17, 2012 at 12:23 AM
Try this code instead.
 var con : float;
     function OnGUI() {
 
         if (!btnTexture) {
             Debug.LogError("Please assign a texture on the inspector");
               }
         if (GUI.Button(Rect(400,200,50,50),btnTexture))
                Application.LoadLevel(1);
            //Debug.Log("Clicked the button with an image");
        }     
    
        con = 1;
     function GetInput(){
        if(con=1){
           steer = -Input.acceleration.y*2;  // hide this line or the line below
           throttle = Mathf.Clamp(Input.GetAxis("Vertical") + rightjs.position.y, -1 , 1);
           booster = Mathf.Clamp(Input.GetAxis("Vertical") + leftjs.position.y, 0 , 1);
        }else{
           steer = Mathf.Clamp(Input.GetAxis("Horizontal") + leftjs.position.x, -1, 1);
           throttle = Mathf.Clamp(Input.GetAxis("Vertical") + rightjs.position.y, -1 , 1);
           booster = Mathf.Clamp(Input.GetAxis("Vertical") + leftjs.position.y, 0 , 1);
     }
 }
 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                