- Home /
How to change a Texture with a Delay
I am trying to do a copy of the Mario with another character. The problem happens when the character have velocity.x == 0 change between 2 textures but goes very fast. I tried using "yield WaitForSeconds(1.5)" but doesn´t work.
Thanks to all of you.
I leave the code here:
function Update ()
{
velocity = Vector3(Input.GetAxis("Horizontal"), 0, 0);
if(velocity.x == 0)
{
StopCoroutine("MovIdle");
StartCoroutine("MovIdle");
}
if(velocity.x > 0)
{
Caminar();
}
}
var imagenes : Texture[];
// This is the first option that i used
function Animacion()
{
for(var img in imagenes)
{
renderer.material.SetTexture("_MainTex", img);
yield WaitForSeconds(retraso);
}
}
// This is the second option that i used
function MovIdle()
{
if(contador == 0)
{
yield WaitForSeconds(retraso);
renderer.material.SetTexture("_MainTex", imagenQuieto1);
contador++;
}
else if(contador == 1)
{
yield WaitForSeconds(retraso);
renderer.material.SetTexture("_MainTex", imagenQuieto2);
contador = 0;
}
}
Comment
Answer by edcarlo · Jan 10, 2014 at 01:17 AM
You dont need to use forloop for 2 textures.
public var t1:Texture;
public var t2:Texture;
function ChangeTex(){
yield WaitForSeconds(1.5);
renderer.material.SetTexture("_MainTex",t1); //renderer.material.mainTexture = t1;
yield WaitForSeconds(1.5);
renderer.material.SetTexture("_MainTex",t2); //renderer.material.mainTexture = t2;
}
//StartCoroutine("ChangeTex");
But, if you want multiple textures:
public var texs : Textures[];
function ChangeTexs()
{
var i : int = 0;
var l : int = texs.length;
while(i < l)
{
renderer.material.SetTexture("_MainTex", texs[i])
i++;
yield WaitForSeconds(1.5);
}
}
Your answer
Follow this Question
Related Questions
Delay Jump 1 Answer
Forced player reset not being delayed 1 Answer
Delay my Scene for few seconds, not sure what wrong 2 Answers
Assigning UV Map to model at runtime 0 Answers