- Home /
How to start animation when GUI button is pressed
I have created simple animation in .fbx in blender and import it into the unity. The animation name is simple_anim and the animation will work fine when i play the button. But now i have added two GUI button and i want when i press gui button then the animation will run..I am new to script and i have written this simple script but its not working fine.
function onGUI()
{
if(GUI.Button(Rect(10,10,150,100),"Button"))
{
animation.play("simple_anim");
}
}
Answer by Adam-Buckner · Feb 05, 2013 at 05:28 AM
Of that is an accurate paste of the code, the first thing I've noticed is the function name is spelled wrong. It should be
function OnGUI() // With a capital O in On
The second is the "P" on "Play" should be UpperCase: http://docs.unity3d.com/Documentation/ScriptReference/Animation.Play.html
animation.Play("MyAnimation");
Your answer

Follow this Question
Related Questions
How do I add NPCs? 2 Answers
Animation on MouseEnter 0 Answers
Animation Vs Animator 2 Answers
Animation Not Playing 1 Answer
Re Enable C# script on camera 1 Answer