- Home /
How do I activate an animation when a gameobject enter the Collider of the other animated object
Hi, I'm new on unity , and I want to make an animation on several gameobjects, with a delay between them. I have 2 animated objects, the first starts when the game is played and the second needs to be triggered only when a gameobject (that is following a way via an other script) enters it's collider( that I've set to be the Trigger). To do so I've made an animation controller tht switches between two states ( 'Idle'and 'playing') in btw those two states the value of a Bool ( named 'trans' changes from true to false) , this value is going to be used in the script as follows : /////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;
public class testcylindre : MonoBehaviour {
public bool trans;
private Animator ani;
private GameObject Player;
void Start () {
}
// Update is called once per frame
void Update () {
ani = GetComponent<Animator> ();
}
void onTriggerEnter(Collider other){
ani.SetBool ("trans", true);
}
void onTriggerExit(Collider other){
ani.SetBool ("trans", false);
}
}
But when I play the scene even when the objects enters the collider the animation doesn't begin, and when i've opened the Animator window while thegame is playing i've noticed tht the Idle state is always looping and it doesn'tgo to the Playing state where the motion is set to the animation.
Any help wiould be welcomed, thanks in advance.
check the ontriggerenter first by putting a Debug.Log. add a script in the ontriggerenter:
Debug.Log("if this message got outputed in console then it means ontriggerenter really did work if not then no");
Answer by mk025 · Aug 04, 2016 at 05:02 AM
I've found the SOLUTIOOON . ok maybe because i'm a noob I didn't knew this, but basically you have to add the property Rigid Body and set kinematic to true and The object coming towards the animated to be other object will be recongnized by it's collider and therefore the animaton will be triggered.
Your answer
Follow this Question
Related Questions
Unity 5 Controlling Animation with UI Button 0 Answers
Hello! I have some issues with animations. 1 Answer
What is the best way nowadays to record a film/movie(mp4) with Unity? 1 Answer
Cant get Animator Controller to work properly 2 Answers
What would be the best way to do something based on the animation state of the character? 0 Answers