I have designed a set of textures for a button (10 textures),when button is not pressed one of them is assigned to it, what i want is when I press the button ,it switches it’s texture from 1 to 10 and show every texture(Like playing an animation when button is pressed),I 've written the following code but it’s not working the way it should!
public int lenth;
public Texture[] text=new Texture[10] ;
Texture sampleText;
public GUISkin skin1;
void Start ()
{
sampleText=text[0];
}
void OnGUI()
{
GUI.skin=skin1;
if (GUI.Button(new Rect(10, 10, lenth, lenth), sampleText))
{
for (int i=1;i<10;i++)
{
sampleText=text*;*
}*
}*
}* }
your for loop set a texture 10 times in one frame... you won't even see it change. you will need a co-routine to run when the button is pressed. and have a delay between those transitions(every 4 frames at 60fps is a good place to start).
This little code snippet is very versatile. We’ve used it for all sorts. Small movie clips, animated electric skin, anything you can think of involving multiple textures. Easily modified to fit many situations.
I think it can be applied to game objects, but for Gui buttons it's not working , or maybe i couldn't set it to . anyway ... thanks for your consideration!
your for loop set a texture 10 times in one frame... you won't even see it change. you will need a co-routine to run when the button is pressed. and have a delay between those transitions(every 4 frames at 60fps is a good place to start).
– Fornoreason1000