• 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 gugu6897 · Jan 07, 2013 at 12:26 PM · sliderheightwidthhorizontal

Horizontal Bar

I'm brazilian and my english is basic.

I'm building a racing game for android. I already created an horizontal bar, but I need to customize its. I need to increase its height and width. I increase its height on GUI, but it display the same small scale in-game.

I need to make a funcionality too. The player will scroll this bar to move the car around. But when this bar is not pressed, I want it get back to value = 0.

Can anyone help me with the scale and the funcionality.

Code:

 static var HoriGUI : float = 0.0;
 static var HoriAll : float = 0.0;
 
 HoriGUI = GUI.HorizontalSlider (Rect (150, 650, 150, 75), HoriAll, -1.0, 1.0);

Thx for the attention.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fafase · Jan 07, 2013 at 12:45 PM

There you go:

 using UnityEngine;
 using System.Collections;
 
 public class GUIScript : MonoBehaviour {
 
     public float hSliderValue;
     void OnGUI()
     {
         if (Input.GetMouseButton(0))
         {
             hSliderValue = GUILayout.HorizontalSlider(hSliderValue, -1.0F, 1.0F,GUILayout.Width(100));
         }
         else
             hSliderValue = GUILayout.HorizontalSlider(0, -1.0F, 1.0F,GUILayout.Width(100));
         GUILayout.Label(hSliderValue.ToString());
     }
 }

Values go from -1 to 1 but it is up to you to modify this.

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 gugu6897 · Jan 07, 2013 at 01:14 PM 0
Share

Thx for the answer, but the game is for android. How can I 'convert' the mouse press by the touch screen holding?

avatar image gugu6897 · Jan 09, 2013 at 12:53 PM 0
Share

$$anonymous$$ouseButton works on touch, thank you very much.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Screen width and height, how to bypass?! 1 Answer

Get height and width of gameobject set with anchors 0 Answers

"Non power of 2" Textures - How to access original size? 3 Answers

Changing height of camera based on device aspect ratio. How? 0 Answers

WebGL - find out vieport size (x,y) 0 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