Unity3D蹲走动画抖动问题求助
Unity3D蹲走动画卡顿(频繁中断重放)问题求助
我无法解决Unity3D中蹲走动画的卡顿问题——动画会不断被中断并重新播放。尝试过设置独立按键、调整Animator节点连接、用if-else分离动画逻辑,也查阅了大量资料,但问题仍未解决,希望能得到帮助和建议。
动画控制代码
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Animation : MonoBehaviour { public GameObject player; private float slowV = 0.3f; private float fastV = 1f; private float blendSpeed = .6f; private float time; private float timeX; private float timeY; private bool crouch; private bool crouch2; void Start() { time = 0; timeX = 0; timeY = 0; crouch = false; crouch2 = false; } void Update() { Debug.Log(crouch); if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.W)) { player.GetComponent<Animator>().SetBool("crouchWalk", true); player.GetComponent<Animator>().SetBool("crouch", false); } else if (Input.GetKey(KeyCode.LeftControl)) { player.GetComponent<Animator>().SetBool("crouch", true); } else { player.GetComponent<Animator>().SetBool("crouchWalk", false); player.GetComponent<Animator>().SetBool("crouch", false); if (Input.GetKey(KeyCode.W)) { if (Input.GetKey(KeyCode.LeftShift)) { time = Mathf.Clamp(time + blendSpeed * Time.deltaTime, -fastV, fastV); player.GetComponent<Animator>().SetFloat("y", time); } else { if (time < slowV) { time = Mathf.Clamp(time + blendSpeed * Time.deltaTime, -fastV, slowV); player.GetComponent<Animator>().SetFloat("y", time); } else { time = Mathf.Clamp(time - blendSpeed * Time.deltaTime, slowV, fastV); player.GetComponent<Animator>().SetFloat("y", time); } } } else if (Input.GetKey(KeyCode.S)) { if (Input.GetKey(KeyCode.LeftShift)) { time = Mathf.Clamp(time - blendSpeed * 2 * Time.deltaTime, -fastV, fastV); player.GetComponent<Animator>().SetFloat("y", time); } else { if (time > -slowV) { time = Mathf.Clamp(time - blendSpeed * Time.deltaTime, -slowV, fastV); player.GetComponent<Animator>().SetFloat("y", time); } else { time = Mathf.Clamp(time + blendSpeed * Time.deltaTime, -fastV, -slowV); player.GetComponent<Animator>().SetFloat("y", time); } } } else { if (time > 0f) { time = Mathf.Clamp(time - blendSpeed * Time.deltaTime, 0f, 1f); } else { time = Mathf.Clamp(time + blendSpeed * Time.deltaTime, -1f, 0f); } player.GetComponent<Animator>().SetFloat("y", time); } if (Input.GetKey(KeyCode.D)) { if (Input.GetKey(KeyCode.LeftShift)) { timeX = Mathf.Clamp(timeX + blendSpeed * 2 * Time.deltaTime, -fastV, fastV); player.GetComponent<Animator>().SetFloat("x", timeX); } else { if (timeX < slowV) { timeX = Mathf.Clamp(timeX + blendSpeed * Time.deltaTime, -fastV, slowV); player.GetComponent<Animator>().SetFloat("x", timeX); } else { timeX = Mathf.Clamp(timeX - blendSpeed * Time.deltaTime, slowV, fastV); player.GetComponent<Animator>().SetFloat("x", timeX); } } } else if (Input.GetKey(KeyCode.A)) { if (Input.GetKey(KeyCode.LeftShift)) { timeX = Mathf.Clamp(timeX - blendSpeed * 2 * Time.deltaTime, -fastV, fastV); player.GetComponent<Animator>().SetFloat("x", timeX); } else { if (timeX > -slowV) { timeX = Mathf.Clamp(timeX - blendSpeed * Time.deltaTime, -slowV, fastV); player.GetComponent<Animator>().SetFloat("x", timeX); } else { timeX = Mathf.Clamp(timeX + blendSpeed * Time.deltaTime, -fastV, -slowV); player.GetComponent<Animator>().SetFloat("x", timeX); } } } else { if (timeX > 0f) { timeX = Mathf.Clamp(timeX - blendSpeed * Time.deltaTime, 0f, 1f); } else { timeX = Mathf.Clamp(timeX + blendSpeed * Time.deltaTime, -1f, 0f); } player.GetComponent<Animator>().SetFloat("x", timeX); } if (Input.GetKey(KeyCode.Space)) { player.GetComponent<Animator>().SetBool("jump", true); } } } }
Animator控制器截图

内容的提问来源于stack exchange,提问作者J C
相关产品推荐
相关产品推荐

