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 INLF · Mar 20, 2015 at 01:19 PM · movescrollbar

Scrollbar to move left and right

Okay so I am trying to make it so that you can move the character left and right with the new UI scrollbar. I am using this script.

 public float moveSpeed;
 
 private float moveVelocity;
 
 public GameObject scrollbar;
 
 void Update () {
     
         moveVelocity = 0f;
 
         if (scrollbar >= 0.5) 
         {
             moveVelocity =  moveSpeed;
         }
         
         if(scrollbar <= 0.5)
         {
             moveVelocity = -moveSpeed;
         }  
 }

So the problem is that I keep getting this error,

Assets/Move.cs(27,21): error CS0019: Operator >' cannot be applied to operands of type UnityEngine.GameObject' and `double'

Comment
Add comment · Show 1
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 AlwaysSunny · Mar 20, 2015 at 07:57 AM 0
Share

http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-scrollbar

Get the bar as a ScrollBar, not a GameObject. Read its .value field. Optionally, set the value back to 0.5f when the user lets go, or use the value's distance from 0.5f to influence the speed of movement.

Also, most things in Unity want floats, not doubles. Qualify your "mixed numbers" with an f unless you actually want a double.

 float foo = 1.5f;
 double bar = 1.5;


1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by spiceboy9994 · Mar 21, 2015 at 12:02 AM

Assuming that your public scrollbar object indeed has an UI.Scrollbar component attached, you should try this

 public GameObject scrollbar;
 //Add a reference to the scrollbar component
 Scrollbar myScrollbar;
 
 void Start() {
   myScrollbar = scrollbar.GetComponent<Scrollbar>();
 }
  
  void Update () {
      
          moveVelocity = 0f;
  
          if (myScrollbar.value >= 0.5) 
          {
              moveVelocity =  moveSpeed;
          }
          
          if(scrollbar.value <= 0.5)
          {
              moveVelocity = -moveSpeed;
          }  
  }

Don't forget to add the reference to the UnityEngine.UI namespace at the beginning of your class so you can have access to the objects. Just go to the top of your class and add:

 using UnityEngine.UI;

Regards

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 INLF · Mar 22, 2015 at 03:12 PM 0
Share

Thank you so much

avatar image spiceboy9994 · Mar 23, 2015 at 04:32 PM 0
Share

If that worked... do you $$anonymous$$d a thumbs up vote? :D?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Move GameObject between two points using Scrollbar 2 Answers

Directional Movement - Input position calculation? 2 Answers

C# move main camra via mouse position on boarders around screen script for RTS Game 0 Answers

translate 2 Answers

Make your player not move during a animation? 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