- Home /
Add Mixing Transform Doesn't Work!!
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;
var mixShootLaserGun : Transform = transform.Find("waistM/back1M/back2M/RclavicleM/RshoulderM/RelbowM/RwristM/Rcannon1M");
animation["laserShoot"].AddMixingTransform(mixShootLaserGun);
var mixMachineGun : Transform = transform.Find("waist/back1/back2/Lclavicle/Lshoulder");
animation["machineGunShoot"].AddMixingTransform(mixMachineGun);
}
function Update () {
if (Input.GetAxis("R_Trigger") > 0.1 && animation.IsPlaying("idle"))
animation.Play("laserShoot");
}
Can anyone see any problems with what I have done? Or help me understand why it isn't working?
Thanks
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.Add$$anonymous$$ixingTransform (UnityEngine.Transform mix) mechGun.Start () (at Assets/$$anonymous$$ech Scripts/mechGun.js:9)
A null reference means it couldn't find something -- probably a bad path. Try printing mix$$anonymous$$achineGun
and 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!
Answer by garner · Apr 07, 2012 at 09:13 AM
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.
Answer by Joevis · Apr 07, 2012 at 03:30 PM
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.
Answer by DJSwiti · Apr 08, 2012 at 10:48 PM
I think you missed some ( and ).
Try with that :
function Update () { if ((Input.GetAxis("R_Trigger") > 0.1) && (animation.IsPlaying("idle")))
animation.Play("laserShoot");
}
Answer by Moj · May 12, 2012 at 06:37 PM
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.
Your answer
Follow this Question
Related Questions
Mixing Animations 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Which transform properties can be set in a scripted animation? 1 Answer
Rotating An Object On Its Axis Once 3 Answers
problem with addmixing transform 1 Answer