- Home /
Help with an animation script that works with multiple objects.
Hey everyone! Right now Im trying to make a game and need help making a script of great value to me and hopefully to others. I want to make a script that can be attached to a collider, when the player enters the script will look for a game object " var ToAnimate : GameObject; " that the user has assigned, it will then look for the objects animations and be able to play them. Problem is that I dont know how to assign animations to variables.
This is how I want the code to work.
code:
var toAnimate : GameObject;
var animation1 : AnimationClip;
var animation2 : AnimationClip;
function OnTriggerEnter (other : Collider)
{
toAnimate.animation.Play("animation1");
}
function OnTriggerExit (other : Collider)
{
toAnimate.animation.Play("animation2");
}
I want to be able to assign my game obj in the inspector as well as the animations that should be played. But It wont work, error message: The animation state animation1 "and 2" could not be played because it couldn't be found!
hope you guys wanna help me out. Cheers.