- Home /
grab weapon script problem
i have this script to play an animation in the characters children. when you click space the character will reach up and grab a sword on his back. this is my script:
function update() { if(Input.GetButtonDown("Jump")) { var animationComp : Animation[] = gameObject.GetComponentsInChildren(Animation); for (var animComp : Animation in animationComp) { animComp.Play("grab sword");
}
}
}
when i click space i get this error: InvalidCastException: Cannot cast from source type to destination type.walker.Update () (at Assets\my scripts\walker.js:21) how do i fix that?
Answer by DaveA · Jan 29, 2011 at 05:33 AM
Try this:
var animationComp : Animation[] = gameObject.GetComponentsInChildren(Animation) as Animation[];
i got this error: NullReferenceException: Object reference not set to an instance of an object walker.Update () (at Assets\my scripts\walker.js:22)
Your answer
Follow this Question
Related Questions
transform array gives error. why? 1 Answer
iTween: Cannot cast from source type to destination type. 1 Answer
InvalidCastException: Cannot cast from source type to destination type. 4 Answers
InvalidCastException when trying to access child components 2 Answers
InvalidCastException: Cannot cast from source type to destination type. ??? 2 Answers