Sequence of textures

Hi!
This script makes a sequence of texture, to create an effect of lights.
My question is, at the start I would like that there was a “specific texture” (that simulates the light off) and I would like create an input, so if I press a key, the animation starts, and if I press the same or another key, return to the “specific texture” at the start (to simulate the light animation off)

This is the script, how can I do this?
Thank you in advance :slight_smile:

using UnityEngine;
using System.Collections;

public class LightAnimator : MonoBehaviour 
{
    public float     speed;
    public Material  material;
    public Texture[] textures;
    
    float frameTime;
    
	void Update() 
    {        
        int numTextures = textures.Length;
        
        if (numTextures == 0)
            return;
            
        frameTime += Time.deltaTime * speed;
        material.mainTexture = textures[(int)Mathf.Abs(frameTime) % numTextures];
        material.SetTexture("_Illum", textures[(int)Mathf.Abs(frameTime) % numTextures]);

	}
}

Maybe I can do a better job of understanding and answering your questions this time. ‘textureOff’ is the texture when the light is off.

using UnityEngine;
using System.Collections;
 
public class LightAnimator : MonoBehaviour 
{
    public float     speed;
    public Material  material;
    public Texture[] textures;
	public Texture   textureOff;
	
	private bool on = false;
 
    float frameTime;
	
	void Start() {
		material.mainTexture = textureOff;
        material.SetTexture("_Illum", textureOff);	
	}
 
    void Update() 
    {     
		if (Input.GetKeyDown(KeyCode.Space)) {
			on = !on;
			if (!on) {
				frameTime = 0.0f;
				material.mainTexture = textureOff;
		        material.SetTexture("_Illum", textureOff);				
			}
		}
		if (on) {
	        int numTextures = textures.Length;
	 
	        if (numTextures == 0)
	            return;
	 
	        frameTime += Time.deltaTime * speed;
	        material.mainTexture = textures[(int)Mathf.Abs(frameTime) % numTextures];
	        material.SetTexture("_Illum", textures[(int)Mathf.Abs(frameTime) % numTextures]);
   	 	}
	}
}