Search Unity

Resolved How to play an animation on button click?

Discussion in 'Scripting' started by cyclSunity, Sep 26, 2020.

  1. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    Hey, making game. So im making a button where you click it and an apple will fly across the screen. First of all, how do I animate? After I make the animation file, then how would I script it to play? Thanks a lot!!!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Definitely start with one of the thousands of Unity animation tutorials out there.

    This would be covered by pretty much any tutorial on interactive UI under Unity.
     
    Dextozz likes this.
  3. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    o_O
     
    kmcpher likes this.
  4. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    cool, but can i have a link?
     
  5. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
  6. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    thank you!
     
  7. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    i found this:
     
  8. ByterExe

    ByterExe

    Joined:
    Feb 15, 2022
    Posts:
    1
    what tf do you mean milion tutorials, there is not even a single one that shows how to play animation when you press a single button. the only thing i need is that my Blink animation plays when i press A or D.
     
  9. Pixelith

    Pixelith

    Joined:
    Jun 24, 2014
    Posts:
    580
     
    Kurt-Dekker likes this.
  10. giorginoedery

    giorginoedery

    Joined:
    Feb 19, 2022
    Posts:
    3
    hey im trying to use the button to play animation, but the animator doesnt show up under functions, pls help! thanks.
     
  11. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    We know animation works, so definitely get back there and try some basic tutorials from Unity.

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Tutorials are a GREAT idea. Tutorials should be used this way:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!

    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!
     
  12. giorginoedery

    giorginoedery

    Joined:
    Feb 19, 2022
    Posts:
    3
    thansk for the sarcasm, but Ive already made the animation and everything else i need, what I am referring to is time 2:48 in the video where drop down menu shows animator after adding an on click () fucntion, ive looked through unity and online a lot to see how I can add it but I haven't found anything that helps (including explaining it to my doggie :p). Thanks again for the help
     
  13. giorginoedery

    giorginoedery

    Joined:
    Feb 19, 2022
    Posts:
    3
    upload_2022-4-26_16-53-16.png
     
  14. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
  15. grafiboys

    grafiboys

    Joined:
    Sep 2, 2020
    Posts:
    9
    Thx so much!!!