Author Topic: Animation on button click.  (Read 8802 times)

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Animation on button click.
« on: April 11, 2013, 12:11:15 PM »
Hi. I'm trying to make a game menu. I have buttons, panels, and almost all things I need. Only thing I don't have are scripts. I really suck at scripting (If I was good at it I wouldn't be asking for help). I have made animation with 2 clips (which moves whole panels), and put it onto Anchor. Now I'm trying to make the animation play on a button press. This is what I got so far:
  1. using UnityEngine;
  2.  
  3. public class ClickEventReceiver : MonoBehaviour
  4. {
  5.         void OnLoadClicked ()
  6.         {
  7.                 UIButtonPlayAnimation(Anchor.Menu1); //I don't really know what to put there. Menu1 is name of the animation clip.
  8.         }
  9. }

Here is error what I get:
Quote
Assets/NewGameM.cs(7,17): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

Any help is appreciated.

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Animation on button click.
« Reply #1 on: April 11, 2013, 03:06:03 PM »
I'm a newbie on NGUI also but I already got tweens (in your case animations) working on my panels when I click on buttons.

Simply:

-Attach UIButtonPlayAnimation to your button
-Fill in the parameters for it right in the inspector. No need to script anything for this.
-Check this example that comes along NGUI, there you'll find what you are looking for: http://www.tasharen.com/ngui/example8.html

In any case, in your script I can see some strange things:

- OnLoadClicked() is not part of the NGUI events as far as I can see. It should be OnClick()
- UIButtonPlayAnimation is a class, you just can't use it like if it is a method...

Stilghar

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Animation on button click.
« Reply #2 on: April 13, 2013, 10:40:48 AM »
Thanks for the reply. I will try to do it trough the inspector. I will give further info if I succeed.

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Animation on button click.
« Reply #3 on: April 13, 2013, 10:47:05 AM »
Oh. Well... I didn't know how to select the animation it should play, but I figured out that I just have to drag the object which has the animation into the blank field (I'm writing it so, if anyone have the same problem as me ( Also, sorry for bad English)).