Код: Выделить всё
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerManager : MonoBehaviour
{
public float speed;
protected Vector3 vector;
public float runSpeed;
private float applyRunSpeed;
private Animator anim;
private void Start()
{
anim = GetComponent();
}
IEnumerator MoveCoroutine()
{
while (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0)
{
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
applyRunSpeed = runSpeed;
}
else
{
applyRunSpeed = 0;
}
vector.Set(Input.GetAxisRaw("Horizontal"),
Input.GetAxisRaw("Vertical"), transform.position.z);
anim.SetFloat("DirX", vector.x);
anim.SetFloat("DirY", vector.y);
anim.SetBool("Idle", false);
if (vector.x != 0 || vector.y != 0)
{
transform.Translate(vector.x * (speed + applyRunSpeed) * Time.deltaTime,
vector.y * (speed + applyRunSpeed) * Time.deltaTime, 0);
}
yield return null;
}
anim.SetBool("Idle", true);
}
private void Update()
{
if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0)
{
StartCoroutine(MoveCoroutine());
}
}
}
/>Но все работало хорошо, пока я не написал код, связанный с анимацией (SetFloat, SetBool), поэтому я подозреваю, что проблема возникла в части, связанной с анимацией.
Или кажется, что компьютер не мог справиться с этим, потому что объем вычислений в части, связанной с сопрограммами, был большим.
Я не удовлетворен ни одним из них.
Подробнее здесь: https://stackoverflow.com/questions/787 ... e-in-unity