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 /
avatar image
0
Question by javanoob · Nov 16, 2012 at 10:14 PM · buttontablet

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
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
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 :)

Comment
Add comment · 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
0

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);
     }
 }
 

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

[meta] Cannot post code - gets cut off 2 Answers

What Am I doing wrong? 1 Answer

Android: Scene change (Application.LoadLevel) has no effect 3 Answers

Changing the code from collision to button 5 Answers

how do i use GUI buttons with a android device(tablet) 2 Answers


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