|
Hi I've made this work on a character currently in my scene, but I just can't get it to work on the newest character I have added. Here is the scripting I have been using function Start () { animation["machineGunShoot"].layer = 14; animation["laserShoot"].layer = 14; } function Update () { if (Input.GetAxis("R_Trigger") > 0.1 && animation.IsPlaying("idle")) } Can anyone see any problems with what I have done? Or help me understand why it isn't working? Thanks
(comments are locked)
|
|
Not sure if this is related, but whenever I set AnimationState.layer to anything other than the default (0), I get a null reference exception. Try removing the part where you change the 'animation["animName"].layer' at the start and see if the exception goes away.
(comments are locked)
|
|
I think you missed some ( and ). Try with that :
(comments are locked)
|
|
The code you're using before the Update function never gets used because you're just playing your standard lasershoot animation. add Debug.Log("Laser Shooting"); before the animation.play("laserShoot"); to see if the if statement is executed.
(comments are locked)
|
|
I just tried that, and the animation is playing. It just isn't isolating the bones I want to play the animation on :/ It should work, because I used the same code for a character in the same game (obviously defining different bones) I just don't understand why it will work for one character and not for another! These can be easier to read if you put short replies to someone as a comment on theirs.
Apr 07 '12 at 04:19 PM
Owen Reynolds
(comments are locked)
|

What's wrong? Are you playing an idle/walk on a lower layer, which should "show through" but isn't (body is just frozen?) That would mean the mixAnim didn't take. Otherwise, maybe it is working, but something else is bad. Can you have Start just play shoot and idle, to check?
Can you check whether mixShootLaserGun is null (path spelled wrong)? UnityScript sometimes won't complain -- just won't do anything.
yeh I'm playing an idle animation on a lower layer.
When the script runs I get an error:
NullReferenceException UnityEngine.AnimationState.AddMixingTransform (UnityEngine.Transform mix) mechGun.Start () (at Assets/Mech Scripts/mechGun.js:9)
A null reference means it couldn't find something -- probably a bad path. Try printing
mixMachineGunand checking each part:Debug.Log(transform.Find("waist");and so on, until it says it can't find it.Ok, how do I go about getting it to print something if it finds "waist"?
Sorry if it's a stupid question but I'm very new to coding :)
It's ok now :) I managed to sort it! It was an error with the path, I had missed out a bone! Duuh!