Before updating to Windows 10 you may need to return your Pro license. More information here

How to play an animation using a trigger???


Trying to figure out how to do this:

I want an animation to be played when my player enters a trigger. As a trigger I used a box and enabled isTrigger, I also tagged the FPS controller as "Player" then I made the script below...

This is my code right now:

function OnTriggerEnter (collision : Collider) {

if (collision.gameObject.tag == "Player"){
animation.Play ("airplane");


Dosen`t seem to work... Then should I attach this script to the trigger or....???

Many thanks in advance! :)

more ▼

asked Apr 18, 2010 at 09:22 PM

avatar image

2 4 4 7

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

There could be a couple of issues:

  1. Make sure your animation is called "airplane" not "Airplane" or "airPlane".

  2. Make sure you used bone based animation to animate the player.

Or what appears to be the most likely error is that you are calling the animation "airplane" on the object this script is on when you want to be calling it in the player.

To fix add this script to the trigger (which cannot move unless you add a kinematic rigidbody) and change your code to this.

if (collision.gameObject.tag == "Player"){
     collision.animation.Play ("airplane"); 
     // we want the player's animation to play, not the trigger's.
more ▼

answered Apr 19, 2010 at 12:04 AM

avatar image

Peter G
18.7k 35 101 222

this script seems to work for the opposite of what the inquirer asked, this script moves the player but we wanted the "object" to move not the player.. thanks anyways.

Apr 20, 2010 at 01:41 AM khalil

No, I can not tell for sure, but it appears to me that there is an empty trigger (which would not have any animations on it) that when the player enters triggers the player's animation.

Apr 20, 2010 at 10:11 AM Peter G
(comments are locked)
10|3000 characters needed characters left

If you haven't figured it out already here is a strong solution.

First animate your object that you want to move.

then give a name to your new AnimationClip.

then attach this Animation to the object itself (uncheck "plays automatically")

We will use a door opening and closing all on one animation (no need to use 2 separate animations for a simple door function.) in this example.

then say:-in Java-

var (dooropenandclose) : AnimationClip; //this is your animation clip.

var (door) : GameObject; //this is your game object that you want to move on trigger.

function OnTriggerEnter(){

animation.Play ("dooropenandclose");


then attach your script to your (box collider is triggered) Object (not camera). Then under the script's variables attach your Object to your script, and your AnimationClip to your script's variables. (you should be able to tab into these open variable slots after you attach your script to your game object if not, your script is not syntaxed correctly.)

enjoy. K

more ▼

answered Apr 20, 2010 at 04:30 AM

avatar image

38 18 17 21

(comments are locked)
10|3000 characters needed characters left

I believe I have followed the instructions to the T and still got this error:

The animation state dooropenandclose could not be played because it couldn't be found! Please attach an animation clip with the name 'dooropenandclose' or call this function only for existing animations.


more ▼

answered Apr 17, 2012 at 05:04 AM

avatar image


(comments are locked)
10|3000 characters needed characters left

i'm getting unexpected token at 1,5 "(" i have no idea how to fix it.

more ▼

answered Nov 26, 2013 at 07:01 PM

avatar image


(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Apr 18, 2010 at 09:22 PM

Seen: 28922 times

Last Updated: Nov 26, 2013 at 07:01 PM