Hi, all! I’m making a game where platforms are randomly spawned at certain intervals. I decided to make it psuedo-random so that the player could still guess which platform they had to get on next. i did this by arranging sets of platforms with an empty at the beginning letting the spawner know that a sequence has started, and an empty at the end letting the spawner know that it has ended so it can spawn the next set. I wanted the spawner to spawn the platforms at the top, so I parented all platforms in he set to the starter empty (which is at the beginning) and added it to a prefab (I also did this because I cannot spawn sets of prefabs) This worked quite well and I was very pleased with it, until I discovered that a certain type of platform wasn’t operating correctly. This was the red platform, and it is supposed to play an animation when a collision occurs. It seems to not play the animation when it is parented to something. I know this is a problem with the script. I just don’t know how to fix it.
here is the script for playing the animation:
private var anim : Animation;
function Start() {
anim = transform.root.GetComponentInChildren( Animation );
}
function OnCollisionEnter(collision : Collision) {
anim.Play();
audio.Play();
}
I think that it is trying to get the animation from its parent. I originally made it like this because a child of the object that was holding the animation had to trigger it, but now that object that was holding it is now a child to something else. How would I fix this?
Thanks!-YA