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....???
Make sure your animation is called "airplane" not "Airplane" or "airPlane".
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.
}
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.)
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.