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 Stef · Jul 17, 2014 at 07:46 PM · c#collidermecanimtransition

mecanim animation transition script

Lads,

I'm using mecanim and trying to trigger a transition from one animation state to another. I have set up a trigger parameter (should I be using bool?), and would like to trigger the transition between the states when a collider is entered. I have colliders on my character, and the colliding game object. The script runs without errors, it just doesn't work. Here's the code I have so far:

 using UnityEngine;
 using System.Collections;
 
 public class Strike_Tower : MonoBehaviour 
 {
     Animator anim;
     
     void Start(){
         anim = GetComponent<Animator>();
     }
     
     void OnTriggerEnter(Collider other) 
     {
         if(other.transform.tag == "Tower")
         {
             anim.SetTrigger("Trigger");
         }
         
     }
 
 }

Any thoughts?

Thanks,

Stef

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by joshh · Jul 17, 2014 at 07:57 PM

Are you using a 2D collider? Is collider on the same object as the animator?

Comment
Add comment · Show 2 · 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 Stef · Jul 17, 2014 at 08:03 PM 0
Share

I am using a capsule collider. The collider is on the same object as the animator.

avatar image joshh · Jul 17, 2014 at 08:29 PM 0
Share

If you put a Debug.Log() in the if(other.transform.tag == "Tower") block does it print? $$anonymous$$y guess without the scene is that OnTriggerEnter isnt happening or the transform tag is not registering as "Tower"

avatar image
0

Answer by AndyMartin458 · Jul 17, 2014 at 08:13 PM

You should be using code to set a parameter, not a trigger in the anim. For Instance, if your mecanim system has a bool called triggering, then you would use anim.SetBool("triggering", true);. Then you would have a transition in your mecanim system when that bool is set to true.

edit__ after reading more about Triggers, they seem to work like booleans except that are set to inactive after they happen. In that case, have you set up a transition to happen when the parameter becomes 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 Stef · Jul 17, 2014 at 08:27 PM 0
Share

Thanks Andy, Yes, I have tried setting up the SetBool trigger as you suggest, but still don't get the result. Also, yes, I have tried setting up the Trigger as you suggest, but still no result... :S. Here's what my code currently looks like: using UnityEngine; using System.Collections;

public class Strike_Tower : $$anonymous$$onoBehaviour { Animator anim;

 void Start(){
     anim = GetComponent<Animator>();
 }
 
 void OnTriggerEnter(Collider col) 
 {
     if(col.gameObject.tag == "Tower")
     {
         anim.SetBool("Hit", true);
     }
     
 }

}

avatar image
0

Answer by Stef · Jul 17, 2014 at 10:41 PM

I was just missing a rigid body collider on my character... duh. Thanks all.

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

23 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

Related Questions

Creating a collider in a gameObject using only code 1 Answer

How to get default animation for layer 0 Answers

Call a Void on Collision 2 Answers

Distribute terrain in zones 3 Answers

Mecanim animator layers 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