So i did a script the camera is okey but when i try to walk or run after 1-2 seonds later Animation stops but character moves.Can you guys help me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementController : MonoBehaviour {
private float speed;
public float walkSpeed = 0.02f;
public float runSpeed = 0.06f;
public float rotationSpeed = 2.5f;
Rigidbody rigidbody;
Animator animator;
CapsuleCollider capsuleCollider;
public Transform cameraTransform;
private float yaw = 0;
private float pitch = 0;
// Start is called before the first frame update
void Start() {
rigidbody = gameObject.GetComponent<Rigidbody>();
animator = gameObject.GetComponent<Animator>();
capsuleCollider = gameObject.GetComponent<CapsuleCollider>();
}
// Update is called once per frame
void Update() {
float z = Input.GetAxis("Vertical") * speed;
float y = Input.GetAxis("Horizontal") * rotationSpeed;
transform.Translate(0, 0, z);
transform.Rotate(0, y, 0);
yaw += rotationSpeed * Input.GetAxis("Mouse X");
pitch -= rotationSpeed * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(0, yaw, 0);
cameraTransform.eulerAngles = new Vector3(pitch, yaw, 0);
if (Input.GetKey(KeyCode.LeftShift)) {
if (Input.GetKey(KeyCode.W)) {
animator.SetBool("IsStartWalking", false);
animator.SetBool("IsIdle", false);
animator.SetBool("IsWalking", false);
animator.SetBool("IsRunning", true);
}
else {
animator.SetBool("IsStartWalking", false);
animator.SetBool("IsIdle", true);
animator.SetBool("IsWalking", false);
animator.SetBool("IsRunning", false);
}
speed = runSpeed;
}
else {
if (Input.GetKey(KeyCode.W))
{
animator.SetBool("IsStartWalking", true);
animator.SetBool("IsIdle", false);
animator.SetBool("IsWalking", false);
animator.SetBool("IsRunning", false);
StartCoroutine(Wait());
animator.SetBool("IsStartWalking", false);
animator.SetBool("IsIdle", false);
animator.SetBool("IsWalking", true);
animator.SetBool("IsRunning", false);
}
else
{
animator.SetBool("IsStartWalking", false);
animator.SetBool("IsIdle", true);
animator.SetBool("IsWalking", false);
animator.SetBool("IsRunning", false);
}
speed = walkSpeed;
}
}
IEnumerator Wait() {
yield return new WaitForSeconds(3);
}
}
animator.SetBool(“IsStartWalking”, true);
animator.SetBool(“IsIdle”, false);
animator.SetBool(“IsWalking”, false);
animator.SetBool(“IsRunning”, false);
StartCoroutine(Wait());
animator.SetBool(“IsStartWalking”, false);
animator.SetBool(“IsIdle”, false);
animator.SetBool(“IsWalking”, true);
animator.SetBool(“IsRunning”, false);
here i wanted to try that first i want to use the StartWalking Animation than i want to use Walking Animation.Is this true or not?
edit
i solved the running Animation Problem but the others are unsolved