- Home /
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 :)
 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]);
 
     }
 }
 
Answer by robertbu · Aug 27, 2013 at 10:56 AM
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]);
             }
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Play sequence of images 0 Answers
What is the best way to implement videos in 2D unity game? 0 Answers
Unity4.5 AnimationCurve - Is the property "_MainTex.rotation" valid ? 0 Answers
1 FPS in Unity Timeline 0 Answers
Custom Pivot Points in Sprite Editor 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                