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?
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.
@$$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());
}
}
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());
}
}
Your answer
Follow this Question
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