- Home /
Animated Object Problem
i made a object so it will animate when i step in a trigger zone however once i do step into the trigger nothing happens, i ticked play automatically to see if it was a problem with the animation and the animation plays however the obj teleports to a different part of the map. this is the script:
using UnityEngine; using System.Collections;
public class triggermove : MonoBehaviour {
//This will be the object that you want to play the animation
//and the die
public GameObject obj;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other){
if(other.name == "TriggerArea"){
//Put inside tha Play() the name of the animation you want to play
obj.animation.Play("move");
//Here we will start a coroutine to wait for the animation to end
//so we can kill the object
StartCoroutine(checkAnimationEnd());
}
}
IEnumerator checkAnimationEnd(){
yield return new WaitForSeconds(obj.animation["move"].length);
Destroy(obj);
}
}
any ideas?
Answer by aldonaletto · Oct 21, 2012 at 04:49 PM
This script should be attached to the object that enters the trigger, since you're comparing the other name to "TriggerArea". If it's attached to the trigger instead, you should check the object that entered the trigger. If the "right object" is the player, as usual, compare its tag to "Player":
public GameObject obj;
void OnTriggerEnter(Collider other){
if(other.tag == "Player"){
obj.animation.Play("move");
//You don't need a coroutine, since Destroy has an optional delay parameter:
Destroy(obj, obj.animation["move"].length);
}
}
Your answer
Follow this Question
Related Questions
Presure plate that triggers an animation 1 Answer
Retrigger animation after play through 0 Answers
call/trigger animation of other object 2 Answers
object animation trigger 0 Answers