Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by AMess · May 02, 2016 at 02:56 PM · button trigger eventsonclickanimation.play

UI Button onClick Events have no "animation.play()"

Hi there,

I have gameobject A with a button-component and gameobject B with an animation-component (legacy since it's cheaper). When I use the buttons "On Click" in the inspector - not in the script, in other words: drag'n'drop the gameobject B into and look at the dropbown-menu, choose the "animation"-component, I can't seem to find the "play"-function. I could use the "blend"-function but I think this costs more than just play without blend. alt text

Did I miss something or do I have to make it with an extra script?

pic.jpg (163.3 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · May 02, 2016 at 03:45 PM 0
Share

No idea, but you can always add a Listener via script calling any function you like.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rknapp · Sep 07, 2018 at 04:35 PM

I believe it is because the Play method on the Animation has a return type of bool, and is therefor not an Action<>. I've tested this by creating other components, and only the void-returning methods show up in the OnClick handler. Here's a little helper component I made to get around it.

 [RequireComponent(typeof(Animation))]
 public class AnimationTrigger : MonoBehaviour
 {
     private Animation _animation;
 
     private void Awake()
     {
         _animation = GetComponent<Animation>();
     }
 
     public void Play()
     {
         _animation?.Play();
     }
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Button OnClick() calling wrong function 1 Answer

My button does not assign any variable value,My OnClick button works with Debug.Log, but doesnt assign any values it should 0 Answers

Add different input for On Click event (UI) 0 Answers

OnClick() animation 0 Answers

How do i make the perfect button? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges