Changing Texture after time has passed

Hey there - Unity noob here. So I’m working on a horror game, where the player uses a smartphone as a flashlight. The flashlight has a time limit of 60 seconds. I want to change the texture of the screen on the smartphone to display a “battery” level as the time decreases. I have written some code but it does not work, but I think will provide the basic idea of how I want it to work and am looking for some guidance. Thanks in advance!

Here’s my code:
public class SmartphoneTextureManager : MonoBehaviour
{

public Texture[] SmartphoneTexture;
public float textureCoolDown = 60;
public bool EnableChange = false;
public Renderer renderer;

// Start is called before the first frame update
void Start()
{
    renderer.material.mainTexture = SmartphoneTexture[0];
}

// Update is called once per frame
void Update()
{

    if(Input.GetKeyDown("E"))
    {
        textureCoolDown -= Time.deltaTime;
        EnableChange = true;
    }

    if(textureCoolDown > 50)
    {
        renderer.material.mainTexture = SmartphoneTexture[1];
    }

    if (textureCoolDown > 40)
    {
        renderer.material.mainTexture = SmartphoneTexture[2];
    }

    if (textureCoolDown > 20)
    {
        renderer.material.mainTexture = SmartphoneTexture[3];
    }

    if (textureCoolDown > 10)
    {
        renderer.material.mainTexture = SmartphoneTexture[4];
    }

    else
    {
        renderer.material.mainTexture = SmartphoneTexture[0];
    }
}

}

Notes: In the array, [0] represents the normal texture, [1] represents green battery, [2] yellow battery, and so forth.

Hello.

You should do it with “else if” not all if. As ypu use if everywhere, code is checking all of them.

if

else if

else if

else if

else

@tormentoarmagedoom Thanks for your comment, however this does not change anything. I’m starting to wonder if I may have planned this incorrectly in the inspector. Also, for some reason my ‘textureCoolDown’ does not count down from 60 when ‘E’ is pressed. Any idea?

@tormentoarmagedoom Thanks for your comment, however this does not change anything. I’m starting to wonder if I may have planned this incorrectly in the inspector. Also, for some reason my ‘textureCoolDown’ does not count down from 60 when ‘E’ is pressed. Any idea?