using UnityEngine;
using System.Collections;
public class myTimer : MonoBehaviour {
public int myInt1;
public int myInt2;
public int myInt3;
void Start()
{
StartCoroutine(ValueFader(0f, 100f, 5f, myInt1));
StartCoroutine(ValueFader(0f, 180f, 5f, myInt2));
StartCoroutine(ValueFader(0f, 115f, 5f, myInt3));
}
void Update()
{
//...
}
public IEnumerator ValueFader(float myStartValue, float myEndValue, float myDuration, out int myValue)
{
float myStartTime = Time.time;
while (Time.time < myStartTime + myDuration)
{
myValue = (int)(myStartValue + ((myEndValue - myStartValue) * ((Time.time - myStartTime) / myDuration)));
yield return null;
}
myValue = myEndValue;
}
void OnGUI()
{
GUI.Label(new Rect(0, 0, 80, 20), "myValue: " + myInt1);
GUI.Label(new Rect(0, 20, 80, 20), "myValue: " + myInt2);
GUI.Label(new Rect(0, 40, 80, 20), "myValue: " + myInt3);
}
}
Unity tells me: Error CS1623: Iterators cannot have ref or out parameters
What I want to do, is to be able to input/reference a specific variabel, whose value will be changed, from myStartValue to myEndValue, over time = myDuration.
Why doesn’t it work? Can it be made to work? If not, how can I do this in a different way? I don’t want to depend on Update(), preferably.
Thank you for your time! :]