user2686299
user2686299

Reputation: 427

Animation is not smooth on devices

I want to animate a texture by changing uvRect.y of RawImage.

public class animation : MonoBehaviour {

public RawImage image;
public Text text;

private Rect rect;

// Use this for initialization
void Start () {
    Application.targetFrameRate = 60;
    rect = image.uvRect;
}

// Update is called once per frame
void FixedUpdate () {
    rect.y += (Time.fixedDeltaTime*0.1f);
    text.text = (Time.fixedDeltaTime * 0.1f).ToString() + "  :   " + Time.fixedDeltaTime + "  :  "+image.uvRect.y;
    image.uvRect = rect;
}
}

In Unity's editor animation is smooth, but on devices (iOS or Android) it's not. There are no other scripts in the scene so CPU is not loaded so much to make animation not smooth.

So why it's so and how to fix it?

Upvotes: 1

Views: 874

Answers (1)

Paweł Marecki
Paweł Marecki

Reputation: 630

It's because you using FixedUpdate(). Try to use Update() instead. FixedUpdate should be used to physics operations.

You should also chande Time.fixedDeltaTime to Time.deltaTime.

FixedUpdate depends on physic steps that you can setup in editor. But Update is based on FPS so your animation will be smoother than in FixedUpdate.

Upvotes: 4

Related Questions