- Home /
Passing a rectangle as a parameter seems to have no effect on original using StartCoRoutine
Hi,
I'm trying to use a function where I pass a Rect as a parameter and modify the properties of that Rect, but it seems to have no effect when using StartCoRoutine. I can pass in the rectangle, but the "configureRectGroup" properties does not change. Is this expected behavior? Thanks!
Here's the relevant source:
public class MainMenu : MonoBehaviour {
public GUISkin mainMenuSkin; public GUISkin configureSkin;
// . Configure vars private Rect configureRectGroup = new Rect (0, 0, 240, 0); private Rect configureRect = new Rect (0, 0, 197, 336); // .
void Start () {
StartCoroutine(ScaleIn(configureRectGroup, 0.333f, 0, configureRect.height));
}
private IEnumerator ScaleIn(Rect rec, float seconds, float fromHeight, float toHeight) { float t = 0.0f;
while (t < 1.0f)
{
t += Time.deltaTime * (1.0f/seconds);
rec.height = Mathf.Lerp(fromHeight, toHeight, Easing.Ease(t, Easing.EaseType.In));
rec.y = Screen.height / 2 - (rec.height / 2);
yield return true;
}
}
}
Is yielding "true" doing anything special? (I honestly don't know) If not, the preferred way is to yield null (waiting for one frame). Yielding values cause boxing and unnecessary overhead. But please fill me in if "true" is used for anything. :)
No, "true" is not doing anything. I'll change it to null, thanks for the tip!
Answer by Peter G · Dec 15, 2010 at 09:23 PM
You would need to pass it by reference (ref and out keywords) since it is a value type, a struct, but:
But in my own experiences Unity does not allow you to pass parameters by reference in iterators like that (using while()
then yield return something
).
Ahh, it's a struct. Yeah, I tried ref and out, which the compiler threw an error. Thanks Peter!
Your answer
Follow this Question
Related Questions
How to stop coroutine with parameters? 3 Answers
How do I assign a Gameobject's reference to a field variable as a parameter in a function? 1 Answer
How to make the Colour parameter in coroutine work with any anything with a colour variable. 2 Answers
How to use a float value from coroutine 1 and use in coroutine 2? 1 Answer
Object reference not set to an instance of an object 1 Answer