- Home /
Detecting Trigger Collision for Mecanim Animator
Hello guys! I'm very noob, just got Unity, and I just watched this Mecanim tutorial: http://www.youtube.com/watch?v=Xx21y9eJq1U and i'm now modifing the scripts from the tutorial to fit my game. I've made a Climbing animation using the Animator, so the character can climb ledges when the Bool "ClimbMed" is On, then I've made some Trigger objects ( Cubes with box colliders, "Is Trigger" checked, etc ) and i want the Bool "ClimbMed" to set On when the Player touches it, Just like the guy does in the tutorial with "JumpDown", but i'm not succeding... The Bool doesn't turns on when the game is running, but the character is obviously inside the "ClimbMedTrigger" Object. When I check the Bool manually while the game is running, the Animation Works and all, so I think the problem is with the collision. Can someone help me? ( sorry for bad english! )
This is the AnimTrigger Script that I've put on the Player: using UnityEngine; using System.Collections;
public class AnimTriggers : MonoBehaviour
{
// Create a reference to the animator component
private Animator animator;
void Start ()
{
// initialise the reference to the animator component
animator = GetComponent<Animator>();
}
// check for colliders with a Trigger collider
// if we are entering something called JumpTrigger, set a bool parameter called JumpDown to true..
void OnTriggerEnter(Collider col)
{
if(col.gameObject.name == "ClimbMedTrigger")
{
animator.SetBool("ClimbMed", true);
}
}
// ..and when leaving the trigger, reset it to false
void OnTriggerExit(Collider col)
{
if(col.gameObject.name == "ClimbMedTrigger")
{
animator.SetBool("ClimbMed", false);
}
}
}
Your answer
Follow this Question
Related Questions
Full Performance On Melee Combat 0 Answers
Detect when a trigger has entered a collider 1 Answer
Particles colliding/triggering Particles. Is it possible? 2 Answers
Trigger Collision Detection 1 Answer
Collision detection delayed 0 Answers