Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Menatombo · Aug 05, 2015 at 07:56 PM · animationtriggermecanimtriggers

Mecanim triggering an animation from object

I've been going crazy trying to figure out how to trigger an animation. My character uses mecanim, and I've been trying to make an animation trigger from inside of mecanim without a keypress. It feels like I've tried everything. I've tried putting an animation list on the character and trying to trigger it from the cube trigger, but it says "animation not found". I've tried to put the animation in the mecanim hierarchy, but still says animation not found. How can I trigger an animation is there some type of code I haven't tried.

I've tried the legacy way, and it will work if I'm not using mecanim, but as soon as I use mecanim it stops working.

I just need to be pushed in the right direction for this.

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 Positive7 · Aug 05, 2015 at 08:05 PM 0
Share

$$anonymous$$ake a new state in Animator add a Transition with a bool and Set it true in OnTriggerEnter() or OnCollisionEnter() or whatever.

2 Replies

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

Answer by TheOneFreeMan · Aug 06, 2015 at 12:42 AM

If you want to make unity play an animation when you collide with another object, you need only a simple script that uses OnCollisionEnter() and also accesses the animator controller. A rough example of some C# code would look like:

anim = GetComponent();

void OnCollisionEnter (Collider other) {

 if (other.tag == "Object Name")
 anim.SetBool ("Name of bool", false);
 else 
     
 anim.SetBool ("Name of bool", true);
     }
Comment
Add comment · Show 1 · 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 Menatombo · Aug 11, 2015 at 07:39 PM 0
Share

Finally understand it. I use an on collision enter with your code modified a bit to suit the rest. But thank you so much. Everyone here has helped out a million and I can finally move on to the next steps of the project.

avatar image
0

Answer by Menatombo · Aug 06, 2015 at 10:59 PM

 using UnityEngine;
 using System.Collections;
 
 public class Animate : MonoBehaviour {
     Animator anim;
     // Use this for initialization
     void Start () {
     
         anim = GetComponent<Animator>();
     }
     
     // Update is called once per frame
         void Update () {
     
     }
 
     void OnCollisionEnter (Collision collision) {
     
         if (gameObject.tag == "t_Trigger_Pole")
         anim.SetBool ("Fight_1", false);
     else 
         
             anim.SetBool ("Fight_1", true);
 }
     }

This is my code to attempt to trigger the mecanim animation. I have a Fight_1 animation set in a pole that is an attack dummy. When you collide with the pole you should start the fight_1 animation. When I put this code in to the pole it says there is no animator attached to pole so it cannot access it.

My question is do I have to put this script on the player character? If so it's going to get messy, but at least it's a step in the right direction.

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

25 People are following this question.

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

Related Questions

Mecanim Trigger Stays too long true 1 Answer

How do I setup a Shooting Trigger to make an Animation play on a Platform? 0 Answers

Totally new noob to mecanim and unity itself - Trigger animation? 0 Answers

Mecanim Trigger getting stuck in 'TRUE' state 9 Answers

Trigger Activated Multiple Times From One Click 2 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