Digital Speedometer wrong update - Unity

by thirteen3054   Last Updated July 11, 2019 15:13 PM - source

Hi I am making a digital speedometer and I want it to change like a normal meter like: if speed is 10 on meter and the new speed is 50 it does not just show 50 on text instead gradually increase it.

here is what I have done:

    int speed;
    int textSpeed;
    int speedfinal;

    public Text text;

    // Update is called once per frame
    void Update()
        speed = GameObject.Find("gamePlayManager").GetComponent<gamePlayManagerScript>().userSpeed;
        textSpeed = int.Parse(text.text);

        speedfinal = (int)Mathf.Lerp(textSpeed, speed, 0.1f);

        text.text = speedfinal.ToString();

I am not sure if lerp is a good choice here to change text but that is what I know. Any idea how to do this. thanks.

Tags : unity c# 2d

Related Questions

Unfortunately game has stopped

Updated July 02, 2019 11:13 AM

How to animate objects in Unity 3D

Updated July 12, 2015 13:05 PM