My first issue is that it automatically plays when I start the game.
Also it dose’nt stop playing when I let go of shift.
using UnityEngine;
using System.Collections;
public class GunMovement : MonoBehaviour {
public AnimationClip walk1;
public bool sprint;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey("w")){
sprint=false;
}
if(Input.GetKey ("w")&&Input.GetButtonDown("Sprint")){
sprint=true;
}
if(Input.GetButtonUp("Sprint")&&Input.GetKey("w")){
sprint=false;
}
if(sprint==false){
animation.Stop("Running");
animation.Play("Walking1");
}
if(sprint==true){
animation.Stop("Walking1");
animation.Play("Running");
}
}
}
For the automatic play issue, go to the object with the animation in the hierarchy and for the animation just uncheck the play automatically box. I think it keeps playing because sprint isn’t changed when the character stops movement. I would use:
using UnityEngine; using System.Collections;
public class sprinthelp : MonoBehaviour { public AnimationClip walk1; public bool sprint;
public bool movement;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!Input.GetKey("w") && !Input.GetButtonDown("Sprint")){
movement=false;
}
else{
movement=true;
}
if (movement == true){
if(Input.GetKey("w")){
sprint=false;
}
if(Input.GetKey ("w")&&Input.GetButtonDown("Sprint")){
sprint=true;
}
if(Input.GetButtonUp("Sprint")&&Input.GetKey("w")){
sprint=false;
}
if(sprint==false){
animation.Stop("Running");
animation.Play("Walking1");
}
if(sprint==true){
animation.Stop("Walking1");
animation.Play("Running");
}
}
} }