Help! Parent Platform with Player

Hi guys, I’m new here and i’m brazilian so forgive my english.

I’m developing a game for my university project and this is the scenario:

  • I have an animated platform(animated on unity), it moves up and down only.
  • I’ve created an GameObject Empty and atached an Box Collider on it, and activated the Trigger (Is Trigger ON);
  • My player have an script that when he touches and iten he collect this iten and change his color to the color of the iten.
  • When the player enters the trigger that is a little bit upper the platform and his color is red, he must be parented to the platform and the animation starts, then he must go up, OnTriggerExit the animation must stop. When i try to parent the player it works fine but when i try to play the animation unity console gives me an error, it says that the animation don’t exist, i know why because the animation is atached to the plataform not in the trigger what i should do to it play the animation just with the trigger validation?

Does anybody have an ideia or suggestion?

Thanks!

Welcome to the forum!

You can play an animation on the platform from the trigger by creating a Transform variable in the trigger’s script and linking it to the platform in the editor. Then, you just call animation.Play on the platform object:-

// Trigger script.
var platformObject: Transform;  // Drag the platform to this variable in the editor.

function OnTriggerEnter(other: Collider) {
  platformObject.animation.Play("AnimName");
}