|
I am having no problems triggering an animation with a collision, but can't quite work out how to trigger an animation from a GUI button click. Thanks! Script used:
The script creates the button fine, but I get an error message that reads: "There is no 'Animation' attached to the "GUI" game object, but a script is trying to access it." after adding:
So, i am evidently only calling the animation, not the object with the animation attached to it, but not sure how to make that link happen. Thanks!
(comments are locked)
|
|
Hm? It's just:
If that's not what you want, please show us your script and explain what exactly isn't working, otherwise we can only guess what you are doing wrong. var mainmenuSkin : GUISkin; function OnGUI () { GUI.skin = mainmenuSkin; GUILayout.BeginArea (Rect (ScreenX, ScreenY, areaWidth, areaHeight)); } GUILayout.EndArea(); } Once i add: animation.Play(GuiCubeMove.anim); after the: if(GUILayout.Button("MoveCube")) I receive a "unknown identifier" error. Double checked the animation name to GuiCubeMove.anim, and tried removing the file extension...totally new to scripting.
Aug 09 '10 at 02:47 AM
DvdRB
That didn't work...let me repost as an answer.
Aug 09 '10 at 02:47 AM
DvdRB
The animation needs to be a component of the same GameObject where your GUI script is attached to. If it is not, and it's not possible for you to restructure the scene accordingly, you first need to find the animated GameObject (or assign it in the Inspector using a public var) first, and then start its animation with something like myAnimatedGameObject.animation.Play("GuiCubeMove"); (you probably don't want to add the file extension .anim, unless the name of your animation also contains that extension when you look at the Animatino component of that object in the Inspector.
Aug 09 '10 at 10:49 AM
Wolfram
OH! Attaching the GUI to my animated object worked perfectly, and brought about yet another "well duh" moment between myself and Unity. I understand the concept of the public variable, not sure how to execute it though...might have to make that another question for later. THANKS!
Aug 11 '10 at 03:16 AM
DvdRB
If you declare a public variable in a script, it will show up in the Inspector when you attach that script to an object. Then you can modify the default value for that variable in the Inspector, without touching the script. This varibal can be anything from a simple int/float number, or even a whole GameObject.
Aug 11 '10 at 10:28 AM
Wolfram
(comments are locked)
|
