- Home /
Question by
FutureTech_Coker · Jun 05, 2015 at 04:12 PM ·
c#animator controlleranimations
I want to add sprinting to my character to transition from anystate does anyone have any Ideas
using UnityEngine;
using System.Collections;
public class soldierAnimatorScript : MonoBehaviour {
private Animator anim;
private float sprint;
private bool sprinting = false;
private HashIDs hash;
private int sprintState = Animator.StringToHash("Sprinting.Sprint");
private float sprintSpeed;
// Use this for initialization
void Awake ()
{
anim = GetComponent<Animator>();
hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<HashIDs>();
}
// Update is called once per frame
void Update ()
{
float move = Input.GetAxis ("Vertical");
anim.SetFloat("Walk", move);
anim.SetFloat("Run", move);
anim.SetFloat("Walk", move);
anim.SetFloat("Run", move);
float strafe = Input.GetAxis ("Horizontal");
anim.SetFloat("Slow", strafe);
anim.SetFloat("Fast", strafe);
anim.SetFloat("Slow", strafe);
anim.SetFloat("Fast", strafe);
}
void Sprinting ()
{
AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(1);
if (Input.GetKeyDown(KeyCode.Q))
{
sprintSpeed = 0.9f;
anim.SetTrigger (sprintState);
sprinting = true;
}
else
{
sprinting = false;
}
}
}
Comment
Also, I was hoping to use the animations Hash IDs script I created for all the animations and I don't quite know where to start. $$anonymous$$y regular runs and walks work but the sprint does not work. I am fairly new to scripting and would appreciate any help I could get. Thanks everyone.