- Home /
Help with changing texture and waiting (Help!)
I have a plane that has a texture on it. I would like to know how to make it change texture, wait then change texture again. Any help would be appreciated.
Answer by pheash · Jul 13, 2012 at 08:25 PM
you can use a yield statement to wait for a certain amount of time. to change the texture you use the renderer.material.mainTexture. you can look up exactly what you are asking here in the scripting reference. http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.WaitForSeconds.html http://docs.unity3d.com/Documentation/ScriptReference/Material-mainTexture.html
if this information does not enable you to write the script you would have to learn about the basics of scripting first, noone here will write you complete scripts.
Hope that helps
Answer by pipercubjl · Jul 13, 2012 at 10:01 PM
Thank you. This is just what I needed. I can write the scripts by myself. (I understand you not wanting to write the scripts for me)
Answer by pipercubjl · Jul 13, 2012 at 10:28 PM
Wait a minute...
This is what I did:
var walk1_tex:Texture;
var walk2_tex:Texture;
var stand_tex : Texture;
var attack_tex : Texture;
var hit_tex : Texture;
function Update(){
StartAnimation();
}
function StartAnimation(){
yield WaitForSeconds (1);
renderer.material.mainTexture = walk1_tex;
yield WaitForSeconds (1);
renderer.material.mainTexture = stand_tex;
yield WaitForSeconds (1);
renderer.material.mainTexture = walk2_tex;
yield WaitForSeconds (1);
renderer.material.mainTexture = stand_tex;
}
There is a lot of stuttering. I think it has to do with the yeilding stuff.
Answer by pheash · Jul 14, 2012 at 07:58 AM
the stuttering is because you are calling StartAnimation() inside your update function. this means every frame it is executing it. what you want is only execute it once (and at the end maybe repeat it..) try calling your StartAnimation inside function Start{}.
Also looking at what you are doing here, there are easier ways to animate characters. search on google for sprite sheets. it is basically all your animation frames in one texture and all you do is shift the UV coordinates to animate. have a look at the 2d mario game tutorial of the walkerboys: http://walkerboystudio.com/html/unity_training___free__.html#unity3game3