- Home /
Animations won't play on command
So I have a script that calls certain animations when events occur. Like if the button for sprinting is pressed, then play the sprint animation. But only a few work, like the walk animation, the idle animation, and the shoot animation. Any ideas as to why these won't play when told to?
var WalkAnim : String = "Walk";
var IdleAnim : String = "Idle";
var FireAnim : String = "Firing";
var AimAnim : String = "AimIdle";
var RunAnim : String = "Run";
var ReloadAnim : String = "Reload";
var PlayWhileAiming = false;
var WalkSpeedModifier : float = 8;
var WalkSpeedMultiplier : float = 2;
var Fire : GameObject;
var Reloading : boolean;
private var DefaultPos : Vector3;
private var Controller : CharacterController;
function Start () {
DefaultPos = transform.localPosition;
Controller = GameObject.FindGameObjectWithTag("Player").GetComponent(CharacterController);
}
function Update () {
if(Input.GetAxis("Vertical")||Input.GetAxis("Horizontal")){
gameObject.animation.CrossFade(WalkAnim,0.4);
gameObject.animation[WalkAnim].speed = Controller.velocity.magnitude / WalkSpeedModifier * WalkSpeedMultiplier;
}
else
{
transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,0.4);
gameObject.animation.CrossFade(IdleAnim);
}
if(Input.GetButton("Fire1") && PlayWhileAiming == false && Fire.GetComponent(FireScript2).CanFire == true){
transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
gameObject.animation.Play(FireAnim);
if(Input.GetButton("Fire2") || Input.GetKey("e") && PlayWhileAiming == false){
transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
gameObject.animation.Stop(WalkAnim);
if(Input.GetKey("q") || Input.GetKey("left shift") && PlayWhileAiming == false){
transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
gameObject.animation.CrossFade(RunAnim);
Reloading = false;
if(Input.GetButton("Reload")) {
Reloading = true;
}
if(Reloading == true){
transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
gameObject.animation.CrossFade(ReloadAnim);
}
}
}
}
}
Have you checked all import settings for the animation rig? $$anonymous$$ake sure thr ones who dont work have the same as the ones who do.
Ive also had an animation problem, looked for days, and finally found out the imported scale was different... There are so many things thay could go wrong, Im just trying to elli$$anonymous$$ate a few already :)
Well I tried calling the animations from an external script, aside from this one, and it works. Apparently, I have too many animations being called in this script, or something..
I see you use animation which is kind of obsolete since $$anonymous$$ecanim came out. I recommend you to use it since it is more clear.
Even though, if you want to keep using legacy animations you still can, but you need to mark every take (.anim file) as legacy. How? Select the animation and right click on the inspector label. Select Debug and change Animation Type to 1 (it should be 2 before you change it).
Try this and tell us if it is fixed.
Ugh.. I wish I had seen this sooner! I went ahead and put the calling for some of the animations into different scripts, and that fixed it all up. I'm not sure if it was the $$anonymous$$ecanim problem or not, but if the issue occurs again I shall definitely try your suggestion. Thanks!
Your answer
Follow this Question
Related Questions
Make ALL animations stop! 1 Answer
Any way to stop a build? 3 Answers
Track time between 1 Answer
Audio won´t stop 0 Answers
What will StopCoroutine exactly do? 2 Answers