- Home /
How to give animation to the on gui button?
Here is my code if (GUI.Button(ResolutionHelper(new Rect(230,390,45,45)),"",playTxtStyle)) { } To the play button i want to give animation..this is under OnGUI.
Post some code so we can give some suggestions! or give info like whether you are using GUI or GUILayout or any other plugin!
And more importantly do accept correct answers if you it helps, tht would encourage others to answer you!
Dhanalaxmi, your given data is insufficient to understand your problem . Please give details about coding and project.
I want to animate the image when i touch the button?
Answer by fafase · Apr 07, 2014 at 11:56 AM
It seems you cannot animate the image inside the button as it takes a texture and not a material. What you could do is store the animation in single textures and animate them by code:
public Texture2D[] textures;
float timer;
float freq;
public float frequency;
private int index;
void Start()
{
freq = 1/frequency;
}
void Update()
{
timer += Time.deltaTime;
if(timer > freq){
timer = 0;
if(++index == textures.Length)index = 0;
}
}
void OnGUI()
{
if(GUI.Button(rect,"", textures[index])){}
}
Your answer
Follow this Question
Related Questions
Unity 5 GUI system 1 Answer
3D Button? 1 Answer
Making texture cover whole button 1 Answer
GUI.DrawTexture on GUI.Button press 1 Answer
A node in a childnode? 1 Answer