|
I am building a FPS (not the tutorial) and I built a series of animations for a gun model using Maya (a .mb file). I have imported the animations, and written a basic script that runs the bolt slide animation when you click the mouse (and fire the weapon) here is the script:
however, when I run this script, I get a "Null reference exception" message in the debug window, what is the error? Thanks
(comments are locked)
|
|
Wow, I just used the animation.Play command and it works fine, case solved. Now, I wonder what the difference between wrapMode and play is...
(comments are locked)
|
|
Most likely there is no animation by the name of "Element 0". Or, the game object that you have attached this script to doesn't have an animation component attached to it at all. Well, "element 0" is the first element of the animation component of gameObject M1.Reload (my weapon) M1.Reload is also the true name of the animation...
Feb 17 '10 at 05:08 PM
Slim
"element 0" or "Element 0" - in your code, you have "Element 0" (upper-case E), and if it's actually called "element 0" (lower-case e) that won't work as keys in dictionaries are case-sensitive. So that might be it. I'm not perfectly sure I understand you correctly, though - if the name of the animation is "M1.Reload", it would have to be animation[M1.Reload"] instead. You should also be able to access the animation via animation[0] though (that would be the first animation component).
Feb 18 '10 at 08:56 AM
jashan
I do not believe it is the name that is the issue, I simplified the game quite a bit and made it so its supposed to only do one thing when the mouse is clicked, run "M1.Reload" But even with this simple program, while I don't get any error message, it simply won't play the animation. When I check the play automatically box in the animation component of the m1 gameObject, the animation plays, which proves that the animation IS there...
Feb 18 '10 at 08:29 PM
Slim
*play on start, my bad.
Feb 18 '10 at 08:30 PM
Slim
(comments are locked)
|

Which line exactly are you getting the NullReferenceException on?
Line 5: animation["Element 0"].wrapMode = WrapMode.Once;