Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Sep 06, 2013 at 07:15 AM by Benproductions1 for the following reason:

Duplicate Question

avatar image
0
Question by kevinspawner · Sep 05, 2013 at 09:38 AM · move

GUI SpaceShip Movement Problem!!! Please help!!

 using UnityEngine;
 using System.Collections;
 
 public class simpleMovement : MonoBehaviour 
 
 {
     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
     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
     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);        
             
         // 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);
     
     rigidbody.AddRelativeForce(0,0,engineSpeed*speed*Time.deltaTime);    
         
     rigidbody.AddRelativeForce(strafe);    
         
         
     }    
 }

How do I use the GUI button press (already I have tried some ways, but am not able to achieve the effect) which is been assigned with respective texture to move the ship in yaw and pitch position. I have found the way to achieve this using keyboard controls, Please some one help me to fix this code for GUI texture. Thanks a lot, If you can please explain a bit, It would be of immense help. Thanks

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Sep 05, 2013 at 10:18 AM 0
Share

Too much code with too little (none at all) explanation

avatar image kevinspawner · Sep 05, 2013 at 10:39 AM 0
Share

Thanks. Sorry about the code it is with less explanation I understand. Am trying to just feed the input to a GUI button which is declared as public. The inputs are declared in axis declaration which is been commented on the code. Now I want that to be controlled with GUI texture. Thanks.

avatar image kevinspawner · Sep 06, 2013 at 02:04 AM 0
Share

Can someone help me please

avatar image getyour411 · Sep 06, 2013 at 02:44 AM 0
Share

I believe you have it backwards. You do an if (GUI.Button) and if that's pressed you set moveLeft=True and in some other part of your script it sees moveLeft=true and it kicks in your movement code; you don't feed input to a GUI button, the button press feeds input to your other stuff.

avatar image kevinspawner · Sep 06, 2013 at 03:12 AM 0
Share

Can you explain a bit with one example may be for one direction, literally am banging my head to understand this. :(

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by getyour411 · Sep 06, 2013 at 03:16 AM

You created two exact questions from the look of it, answered the other.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Sep 06, 2013 at 07:15 AM 0
Share

Because of this I'll close this question :)

avatar image kevinspawner · Sep 06, 2013 at 07:19 AM 0
Share

Sorry, for posting twice. Am not much familiar with this site. You can close this question. $$anonymous$$y mistake, apologize.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Lerping the GUI, problem with doing it again 1 Answer

How do i repeat the Lerp movement? 1 Answer

Hit problem unity 1 Answer

Move back to starting point? 1 Answer

How can I move left and right when jumpigng? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges