I want a button to activate an animation in a model called “Leopard”. I did this:
function OnGUI () {
// Make a background box
GUI.Box (Rect (10,10,85,145), “Actions”);
// Make buttons
if (GUI.Button (Rect (12,40,80,20), “idle”)) {
animation.Find(“Leopard”).Play(“idle”);
}
}
Just as guess. Would something like this work, or do I have to make a script for the model and target a function in that script?
I just bout Unity, so I know nothing! Thanks for any help.
i think what you want is that:
var myLeopard : Transform;
function OnGUI () {
// Make a background box
GUI.Box (Rect (10,10,85,145), "Actions");
// Make buttons
if (GUI.Button (Rect (12,40,80,20), "idle")) {
myLeopard.gameObject.animation.Play("idle");
}
}
save and select the gameobject in the scene, that holds the script above and drag your leopard object onto the “My Leopard” property
Thanks, I’ll give that a try.
I tried it a few different ways, and safari crashes every time I press a button with the script on it…
weird.
Well, thanks, I fixed it and got it to work, but odd that Unity could crash the browser like that.