- Home /
Animator not registering changes in parameters.
I have recently begun learning Mecanim. I did the Unity tutorial without issue but when I created a simple test with my own custom animation however the script does not seem to register button presses. I feel like I made an obvious error as I have only recently started using C# for unity due to the fact that I couldn't find any instruction on Mecanim for Javascript. Any help would be appreciated.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof (Animator))]
public class caseset : MonoBehaviour {
public static Animator anim;
static bool wepmode = false;
static bool wepmode2 = true;
AnimatorStateInfo currentBaseState;
//static int Wep = Animator.StringToHash("Base Layer.WeaponLower);
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
void Update() {
if (Input.GetKeyDown("space"))
print("space key was pressed");
anim.SetBool("wep", true);
//print (anim.GetBool ("wep"));
}
// Update is called once per frame
void FixedUpdate () {
bool h = Input.GetButton("space");
float v = Input.GetAxis ("Vertical");
anim.SetFloat ("vert", v);
anim.SetBool ("wep", h);
wepmode = anim.GetBool("wep");
currentBaseState = anim.GetCurrentAnimatorStateInfo (0);
if(Input.GetButton("space")) {
anim.SetBool("wep", true);
wepmode = true;
}
}
}
By script not registering button presses--is the print command not working?(I normally use Debug.Log("message here")--I find it's a bit more reliable.
If you are getting that message, are the parameters in the Animator window being flagged true/false and the float being updated with a number while the game is running in the editor?
Also, I'm assu$$anonymous$$g you mean for this code to both print and set the animator state if the If clause is true--in this case it's just printing a message and every update the "wep" is set to true:
if (Input.Get$$anonymous$$eyDown("space"))
print("space key was pressed");
anim.SetBool("wep", true);
//print (anim.GetBool ("wep"));
Should be changed to:
if (Input.Get$$anonymous$$eyDown("space")){//OPENING BRAC$$anonymous$$ET
print("space key was pressed");
anim.SetBool("wep", true);
//print (anim.GetBool ("wep"));
}//CLOSING BRAC$$anonymous$$ET
You want all that block of code ONLY being ran if the if statement is true--otherwise it will just run the first line and treat the second as separate from the if statement.
Your answer
Follow this Question
Related Questions
Mecanim "trigger" parameter behaviour with multiple animator layers 1 Answer
Animator component prevents NavMeshAgent from disabling/enabling dynamically 0 Answers
Is there a way to change the WrapMode of all Animations in a Mecanim Animator? 1 Answer
NavMeshAgent animation - sliding 2 Answers
Not able to use a Vector as a condition in Mecanim? 2 Answers