简体   繁体   中英

Unity Button Animation

Does anyone know a possible way for an animation that makes it so when a button gets clicked text pops up above the button that says [Clicked]. It must fade away after 3 seconds and it continues to go up. (The text will move up.)

Pretend like this is how it would look

Clicked but faded away

Clicked

Clicked

Clicked

Button

(Unity Using C#)

How about using a Prefab for this?

You'd create a Prefab with a root object and a text label as a child. Then you animate the text label upwards and fading out over three seconds using the Unity animation window.

On button click, you instantiate the prefab, make it a child of the button, and position it at the same position as your button AND auto-destroy it after 3 seconds.

Here's a code example, pretending that your prefab name is " myAnimatedText "

GameObject animatedButtonText = Instantiate(Resources.Load("myAnimatedText"), transform);
animatedButtonText.transform.position = transform.position;
Destroy(animatedButtonText, 3.0f);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM