- Home /
Anyway to pass by reference in a IEnumerator or something?
So I need help with a way to pass castBarCoords by reference in order to change it's position on the canvas.Any help or ideas would be appreciate
Update(){
...
if (player.casting==true) {
MoveCastBar(castBarCoords,castStartPos,castEndPos,player.castTime);
}
...}
private IEnumerator MoveCastBar(ref RectTransform castBarCoords, Vector3 start, Vector3 end,float castTime){
float timeLeft = Time.deltaTime;
float speed = 1.0f / castTime;
float progress = 0.0f;
while (progress<=1.0) {
castBarCoords.position = Vector3.Lerp(castStartPos, castEndPos, progress);
progress+=speed*Time.deltaTime;
timeLeft+=Time.deltaTime;
yield return null;
}
castBarCoords.position = castEndPos;
}
I think you need to yield return something, and also use StartCoroutine() to use IEnumerators.
Answer by fafase · Oct 14, 2015 at 06:02 PM
Answer is simple, you cannot use ref in coroutine.
But your issue does not require to pass by reference anyway. You are accessing members of RectTransform object, so it is fine.
If you were to modify castBarCoords like so
castBarCoords = otherRectTransform;
then yes you would require some kind of ref pattern.
I was kinda tired and wasn't thinking too well...thank you
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Component passing self to method 1 Answer
how to reference a javascript variables in a c# code. 0 Answers
Reference creator of gameObject 1 Answer