Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by ZachAttack9280 · Sep 27, 2015 at 07:38 PM · resetprogress-bar

Reset Value

So im trying to reset the slider (fill) value.

Whole code: using System.Collections; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI;

 public class Slider : MonoBehaviour {
     public UnityEngine.UI.Slider barvalue ;
         private float maxslidervalue = 100;
         public int jump;                 
 
     void Update(){
         if (barvalue = 100) {
             (barvalue = 0)
         } else {
             barvalue == barvalue;
         }
     }
     
     //this makes the progress bar load in 1second intervals with a value of "jump"
 IEnumerator IncreaseSliderValue() {  //Instead of incrementing value in start function. Put your code into a coroutine.
         for (int val = 0; val <= maxslidervalue; val+=jump) {
             barvalue.value = val;
             print (barvalue.value);
             yield return new WaitForSeconds (0.010f);
         
         }
     }
     
     //Creat a new method which will call above coroutine when the Button is clicked.
     public void StartSLider(){
         StartCoroutine(IncreaseSliderValue());
     }
 }

The reset part of the upper code:

 void Update(){
         if (barvalue = 100) {
             (barvalue = 0)
         } else {
             barvalue == barvalue;
         }
     }
     

But i get the error: Assets/Slider.cs(15,17): error CS1525: Unexpected symbol `}'

Is there anything wrong?

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
1

Answer by MadDevil · Sep 28, 2015 at 05:49 AM

there are 2 mistakes in your code

1) you are missing a semicolon in if condition in your update. it should be " barvalue = 0; " 2) in else you cannot use '==' as it is used to compare two variables, it cannot be used for assignment.

Comment
Add comment · Show 5 · 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 ZachAttack9280 · Sep 28, 2015 at 09:37 PM 0
Share

@$$anonymous$$adDevil ok but now i get this Assets/Slider.cs(14,39): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

and

NullReferenceException: Object reference not set to an instance of an object UnityEngine.UI.Graphic.OnRebuildRequested () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:399) UnityEngine.UI.GraphicRebuildTracker.OnRebuildRequested () (at

Code: using System.Collections; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI;

 public class Slider : $$anonymous$$onoBehaviour {
     public UnityEngine.UI.Slider barvalue ;
         private float maxslidervalue = 100;
         public int jump;                 
 
     void Update(){
         if (barvalue = 100) {
             (barvalue = 0);
         } else {
             barvalue = barvalue;
         }
     }
     
     //this makes the progress bar load in 1second intervals with a value of "jump"
 IEnumerator IncreaseSliderValue() {  //Ins$$anonymous$$d of incrementing value in start function. Put your code into a coroutine.
         for (int val = 0; val <= maxslidervalue; val+=jump) {
             barvalue.value = val;
             print (barvalue.value);
             yield return new WaitForSeconds (0.010f);
         
         }
     }
     
     //Creat a new method which will call above coroutine when the Button is clicked.
     public void StartSLider(){
         StartCoroutine(IncreaseSliderValue());
         }

}

avatar image MadDevil ZachAttack9280 · Sep 29, 2015 at 05:44 AM 0
Share

public class Slider : $$anonymous$$onoBehaviour { public UnityEngine.UI.Slider barvalue ; private float maxslidervalue = 100f; public int jump;

 void Update()
 {
     if (barvalue.value.Equals(100f))
     {
         barvalue.value = 0f;
     }
     else 
     {
         barvalue = barvalue;
     }
 }
 
 //this makes the progress bar load in 1second intervals with a value of "jump"
 IEnumerator IncreaseSliderValue() 
 {  //Ins$$anonymous$$d of incrementing value in start function. Put your code into a coroutine.
     for (int val = 0; val <= maxslidervalue; val+=jump) 
     {
         barvalue.value = val;
         print (barvalue.value);
         yield return new WaitForSeconds (0.010f);
         
     }
 }
 
 //Creat a new method which will call above coroutine when the Button is clicked.
 public void StartSLider()
 {
     StartCoroutine(IncreaseSliderValue());
 }

}

avatar image MadDevil MadDevil · Sep 29, 2015 at 05:45 AM 0
Share

try the above code. I have solved the issue.

Show more comments

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Variable being reset to default after being set 1 Answer

How do I restart a scene on collision? 0 Answers

SetActive(false), and then back to true to call OnEnable 0 Answers

Progress Bar and lerps 0 Answers

Rotation Troubles 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