- Home /
GUI movement Control. Please Help!!! Thanks
 {
     public float speed = 0.00f;
     public float rotSpeed = 10.0f;
     public float strafeSpeed =10.0f;
     private float engineSpeed = 0.0f;
     public float pitchConstant = 1.0f;
     public float yawConstant = 0.0f;
     public GameObject boostersprefab;
     public GameObject boosterPos;
         
     private GameObject instantiated;
     private bool instanBoostersExist;        
     
     // GUI texture
     
     public GUITexture forwardPitchButton;
     public GUITexture backwardPitchButton;
     public GUITexture leftPitchButton;
     public GUITexture rightPitchButton;        
     
     
     
     
     // Booster Start Function (Instantiate the particles)
     void boostersStart()        
     {  
         if(instanBoostersExist == false)    
         
         {            
           instantiated = (GameObject)Instantiate(boostersprefab, boosterPos.transform.position, boosterPos.transform.rotation);
           instantiated.transform.parent    = boosterPos.transform;
           instanBoostersExist = true;            
         }        
     }        
     
     // Booster Stop Function (Stop Instantiating the particles)
     void boosterStop()
     {        
         if (instanBoostersExist == true)
         {        
             Destroy(instantiated,0.2f);
             instanBoostersExist = false;
         }    
     }
     
         
     
     void Update()
         
     {        
     // Axis Declaration    
     float pitch = Input.GetAxis("Pitch")*pitchConstant;         
     float yaw   = Input.GetAxis  ("Yaw")*yawConstant;        
     float roll =  Input.GetAxis ("Roll");
     float gas =   Input.GetAxis ("Gas");        
     
         
     Vector3 strafe = new Vector3 (Input.GetAxis("Horizontal")*strafeSpeed*Time.deltaTime,Input.GetAxis("Vertical")*strafeSpeed*Time.deltaTime,0);// Vertical and Horizontal Axis is feeded to the strafe movement.        
             
         // Engine Mechanism        
         
          if (engineSpeed <10 && engineSpeed > -3)
          {
           engineSpeed += gas;            
           boostersStart();          
          }
         
          if(engineSpeed > 10)
          {
           engineSpeed = (9.99f);    
          }
         
          if (engineSpeed<-3)
          {
           engineSpeed = (-2.99f);        
          }
         
           else if(Input.GetKey("z"))// Brake
          {
           engineSpeed = (0.00f);
           boosterStop();          
          }    
     
      
         
         
         
         
     // SpaceShip Physics Movement
         
     rigidbody.AddRelativeTorque(pitch*rotSpeed*Time.deltaTime,yaw*rotSpeed*Time.deltaTime,roll*rotSpeed*Time.deltaTime); // realative torque is added
     
     rigidbody.AddRelativeForce(0,0,engineSpeed*speed*Time.deltaTime); // relative force    
         
     rigidbody.AddRelativeForce(strafe);    // rigidbody added to the strafe movement
         
         
     }    
 }
How do I feed the movement function to GUI button?, I already created GUI texture and declared it int he program. I tried many way but couldn't get it working. i just want to move the ship when the GUI button is pressed instead of keyboard controls. Please help me out. Thanks a lot.
if(GUI.Button (...this button...) move left
if(GUI.Button (...this button...) move right
etc.
Thanks. $$anonymous$$uch appreciated. Do I need to create a gui function or how do i achieve this?
Can you write for one direction. I can understand it better, Thanks a lot for your effort.
Thanks. So I need to create a bool isBraking and set it to true on void OnGUI right?
Answer by getyour411 · Sep 06, 2013 at 03:15 AM
Change this
  else if(Input.GetKey("z"))// Brake
 {
 engineSpeed = (0.00f);
 boosterStop();
 }
 
to something like
 if(isBraking) {
 engineSpeed = (0.00f);
 boosterStop();
 }
in your OnGUI you'll have button named 'Brake'
 if(GUI.Button,.....,) isBraking=true;
Sorry, Thanks for your reply. Am trying out now. I answered in the other question.
     public GameObject boosterPos;
         
     private GameObject instantiated;
     private bool       instanBoostersExist;
     
     public bool isBraking = false;
     //public bool isGas     = false;
     
     // GUI textures
     
     public GUITexture forward$$anonymous$$chButton;
     public GUITexture backward$$anonymous$$chButton;
     public GUITexture left$$anonymous$$chButton;
     public GUITexture right$$anonymous$$chButton;    
     
     public Texture2D brakeButton = null;
     public Texture2D gasButton =null;
     
     
     
     void OnGUI()
     {
     
       if(GUI.Button(new Rect(Screen.width /2 +100, Screen.height /2 +100, brakeButton.width,brakeButton.height),brakeButton)) 
             
         {            
           isBraking=true;    
         }
         
      if(GUI.Button(new Rect(Screen.width /2 -63, Screen.height /2 -63, gasButton.width,gasButton.height),gasButton))    
         {
               
         }    
         
     }
     
     
     
     
     // Booster Start Function (Instantiate the particles)
     void boostersStart()        
     {  
         if(instanBoostersExist == false)    
         
         {            
           instantiated = (GameObject)Instantiate(boostersprefab, boosterPos.transform.position, boosterPos.transform.rotation);
           instantiated.transform.parent    = boosterPos.transform;
           instanBoostersExist = true;            
         }        
     }        
     
     
     // Booster Stop Function (Stop Instantiating the particles)
     void boosterStop()
     {        
         if (instanBoostersExist == true)
         {        
             Destroy(instantiated,0.2f);
             instanBoostersExist = false;
         }    
     }    
         
     
     void Update()
         
     {        
     // Axis Declaration    
     float pitch =   Input.GetAxis  ("$$anonymous$$ch")*pitchConstant;         
     float yaw   =   Input.GetAxis  ("Yaw")*yawConstant;        
     float roll  =   Input.GetAxis  ("Roll");
     float gas   =   Input.GetAxis  ("Gas");        
     
         
     Vector3 strafe = new Vector3 (Input.GetAxis("Horizontal")*strafeSpeed*Time.deltaTime,Input.GetAxis("Vertical")*strafeSpeed*Time.deltaTime,0);// Vertical and Horizontal Axis is feeded to the strafe movement.        
             
         // Engine $$anonymous$$echanism        
         
          if (engineSpeed <10 && engineSpeed > -3 )
          {
           engineSpeed += gas;            
           boostersStart();          
          }
         
          if(engineSpeed > 10)
          {
           engineSpeed = (9.99f);    
          }
         
          if (engineSpeed<-3)
          {
           engineSpeed = (-2.99f);        
          }
         
          if(isBraking)               // Brake
          {
           engineSpeed = (0.00f);
           boosterStop();          
          }     
         
         
         
         
     // SpaceShip Physics $$anonymous$$ovement
         
     rigidbody.AddRelativeTorque(pitch*rotSpeed*Time.deltaTime,yaw*rotSpeed*Time.deltaTime,roll*rotSpeed*Time.deltaTime); // realative torque is added
     
     rigidbody.AddRelativeForce(0,0,engineSpeed*speed*Time.deltaTime); // relative force    
         
     rigidbody.AddRelativeForce(strafe);    // rigidbody added to the strafe movement
         
         
     }    
 }
How do I make the gas button work, I tried the same boolean way like you said int he earlier comment, but it doesn't work.
Your answer
 
 
             Follow this Question
Related Questions
Why does my player want to fly? 1 Answer
Stopping an object immediately 1 Answer
How to Convert each 2D Array to GameObject 2 Answers
Taking a hit 3 Answers
Rotate game object and then return to its original rotation 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                