- Home /
Make parent animate
I currently have code that makes an object animate. I want to move the code to a child of it so that oncollision of that child the specific animation would occur. Is there a way I can tell the parent to animate?
Current Code C#:
using UnityEngine;
using System.Collections;
public class TriggerAnimation : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.CompareTag("Player"))
{
animation.CrossFade("Take 001");
}
}
}
Comment
Best Answer
Answer by sneftel · Jun 20, 2011 at 06:19 PM
Sure, a gameobject's parent gameobject is accessible as transform.parent.gameObject, so you can do transform.parent.animation.CrossFade(whatever). (Though when you've got chains that long, it's a good idea to break them up with temporary variables.)
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Accessing a child's animation to play or stop it 2 Answers
Make animation go to child.,Make animation go to child 1 Answer
Children won't animate 2 Answers
Child Parent problem 1 Answer