- Home /
Triggering Another GameObject's Animator Triggers
I'm making a boxing game in Unity, using the latest version of Unity. I used Mixamo's Fuse software to make my main character. I put a box collider on her upper body (also known as "Tops") and set it as a trigger. "Tops" is a child of the main character's model. I put in an animation for her to react when she gets a hit to her body. I set a trigger for this animation. I put another collider on the enemy's foot to trigger a collision when it contacts the player's "Tops". The collision is working: I set the debug to let me know when the enemy's foot's collider enters the player's Tops collider. Both models (the main Player and the enemy) have been set as rigidbodies, as have the Tops and the enemy's right leg.
The problem is, that the animation for the main character's reaction is NOT being triggered when the collision occurs.
Here is the code for my Tops' collider. The Tops is a child of my model, and I have attached this script on my Tops:
using UnityEngine;
using System.Collections;
public class BodyCollider : MonoBehaviour {
GameObject player;
Animator animator;
// Use this for initialization
void Start ()
{
player = GameObject.FindGameObjectWithTag ("Player");
animator = player.GetComponent<Animator> ();
}
void OnTriggerEnter(Collider other)
{
animator.SetTrigger ("body_hit_Trigger");
Debug.Log ("Body collision detected.");
}
// Update is called once per frame
void Update () {
}
}
animator.SetTrigger does NOT work for me. How do I trigger the Player's GutHit animation from inside the Tops' script?
I have attached a pic of the Animator controller for my main Player where you can see the various triggers I have assigned. I assigned "GutHit" to the "body_hit_Trigger" trigger.
Your answer
Follow this Question
Related Questions
Multiple Game Objects with single Animator? 1 Answer
why I have to anim.getComponent in update() function when I had done in Start () function 2 Answers
Slow down an animation from Script - C# 0 Answers
Error with my strafe animations on player 0 Answers
An empty idle animation overwrites values set through the FixedUpdate code 0 Answers