- Home /
Trying to access mecanim floats C#,
So i have been working with makehuman inside of unity trying to get it to work. I need to access the floats inside of mecanim and change them real time. Here is my code, i am a beginner and have zero experience in the field to constructive criticism is welcome. I am using c#.
using UnityEngine;
using System.Collections;
public class Move : MonoBehaviour {
// Use this for initialization
void Start () {
Animator anim;
anim = GetComponent<Animator>();
float sprint = 0.0f;
}
// Update is called once per frame
void Update () {
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
anim.SetFloat ("walk", v);
anim.SetFloat ("Turn", h);
anim.SetFloat ("Sprint", sprint);
if(Input.GetButtonDown ("Shift")){
sprint = 0.2f;
}
else{
sprint = 0.0f;
}
}
}
Answer by Socrates · Mar 23, 2015 at 02:48 AM
You have not listed any errors, but there are two things that immediately stand out to me:
On line 23, "walk" is lower case, but line 24 has "Turn" capitalized and line 25 has "Sprint" capitalized. Either your variable naming in the animation controller is inconsistent, or you have an error there.
Line 25 sets the "Sprint" to sprint, but you don't actually update the value of sprint based off of the Shift key until line 27. That would make your sprint change the frame after you press or release the Shift key.
To get better assistance, more information on what isn't working as you expect or what errors you are getting would be helpful.
The problem was there was not any errors, Just $$anonymous$$e. I appreciate the answer.