Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by jhonilson · Feb 18, 2015 at 07:50 AM · animationgui button

GUI button-play a 3d model animation

HI Everyone. I import a FBX 3d model and i Split the animation in 4 parts. I added a gui button (canvas) to the scene and i want play an animation when i clicked it. I test this code :

 // Update is called once per frame
  void Update () 
  {
      if(Input.GetKeyDown("w")){
          animation.Play("caminar");
      }
      if(Input.GetKeyDown("a")){
          animation.Play("arrodillarse");
      }
      if(Input.GetButtonDown("Jump")){
          animation.Play("brazos");
      }
  }


and work fine using the keyboard. But i want do the same with the gui button.

I write this code:

 using UnityEngine;
  using System.Collections;
  
  public class MouseButton : MonoBehaviour {
  
      void OnMouseDown()
      {
          Debug.Log("FUNCIONA_1");
      }
      void OnMouseUp()
      {
          Debug.Log("FUNCIONA_2");
      }
  
  }

And i add it to the button but doesnt work!!

Can i someone how i could do that? Thanks

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by dorpeleg · Feb 18, 2015 at 08:08 AM

The new GUI system works a bit differently. What you need to do is something like:

 public void LogTest()
 {
    Debug.Log("FUNCIONA_1");
 }

and in your button component, chose the object that contains the script and chose the function.

Check this UI BUTTON (about 8 minutes in).

Comment
Add comment · Show 3 · 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
avatar image jhonilson · Feb 18, 2015 at 02:27 PM 0
Share

O$$anonymous$$, I will try it tonight and i will reply if i have success, while i will watch the video that you suggest me. Thank You!

avatar image jhonilson · Feb 19, 2015 at 01:13 PM 0
Share

HI dorpeleg, I did it!!!

I just write a script with:

      public void Walk(){
         animation.Play("walk");
      }

Then i added this script to my 3d model. After that i added the 3d model to the button and then i set the function "Walk" (it must apper in the combo list when you add the 3d model), and ready!! The video help me so much. Now i will try to test the button in a touch device, I guess the process must be similar?

Thank you very much.!

avatar image dorpeleg · Feb 19, 2015 at 04:48 PM 0
Share

The UI should be working with touch by default. If my answer helped you, please mark as answered :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Can I make animations snap to a frame? 1 Answer

Moving a group of GUI Buttons connected by several HingeJoint2D (like chains) using animation messes everything. How else can I do it? 1 Answer

Unity GUI 4.6 stops animation 0 Answers


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