Support => NGUI 3 Support => Topic started by: webik150 on April 11, 2013, 12:11:15 PM
Title: Animation on button click.
Post by: webik150 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:
usingUnityEngine;
publicclass ClickEventReceiver : MonoBehaviour
{
void OnLoadClicked ()
{
UIButtonPlayAnimation(Anchor.Menu1);//I don't really know what to put there. Menu1 is name of the animation clip.
}
}
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.
Title: Re: Animation on button click.
Post by: stilghar 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 (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
Title: Re: Animation on button click.
Post by: webik150 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.
Title: Re: Animation on button click.
Post by: webik150 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)).