aqeel
aqeel

Reputation: 77

Why do await Task.Delay(10); stops execution in unity Web-GL?

I am using await Task.Delay(10); in unity C# for delay .After build and run in Web-GL format .The execution stops at this line that has delay .When I remove the delay it executes.

while (XAxiscurrentXpos <= -izvalue) 
{ 
    await Task.Delay(10); 

    XAxiscurrentXpos += 0.001f; 
    Vector3 posx = new Vector3(XAxiscurrentXpos, XAxisposition.y, XAxisposition.z); 
    XAxis.transform.localPosition = posx; 
}

Upvotes: 0

Views: 4201

Answers (2)

aqeel
aqeel

Reputation: 77

I have solution by using UniTask. UniTask Link is here

Upvotes: 2

derHugo
derHugo

Reputation: 90683

So now knowing what you are actually trying to do instead of your task at all you rather want to use e.g.

public class MoveObject : MonoBehaviour
{
    public Transform XAxis;
    public float desiredUnitsPerSecond;

    // This is called once a frame by Unity
    private void Update()
    {
        if(XAxis.localPosition.x <= -izvalue)
        { 
            XAxis.localPosition += Vector3.right * desiredUnitsPerSecond * Time.deltaTime;
        }
    }
}

this moves your object with the linear speed of desiredUnitsPerSecond in its local right direction as long as it is left of -izvalue.

Upvotes: -1

Related Questions