Pun-01/Assets/Scripts/PlayerAnimatorManager.cs
2022-07-08 09:14:55 +08:00

54 lines
1.3 KiB
C#

using Photon.Pun;
using UnityEngine;
namespace cc.ivanli.pun01
{
public class PlayerAnimatorManager : MonoBehaviourPun
{
private Animator animator;
[SerializeField]
private float directionDampTime = 0.25f;
void Start()
{
animator = GetComponent<Animator>();
if (!animator)
{
Debug.LogError("PlayerAnimatorManager is Missing Animator Component", this);
}
}
void Update()
{
if (!animator)
{
return;
}
if (photonView.IsMine == false && PhotonNetwork.IsConnected == true)
{
return;
}
var stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.IsName("Base Layer.Run")) {
if (Input.GetButtonDown("Fire2")) {
animator.SetTrigger("Jump");
}
}
var h = Input.GetAxis("Horizontal");
var v = Input.GetAxis("Vertical");
if (v < 0)
{
v = 0;
}
animator.SetFloat("Speed", h * h + v * v);
animator.SetFloat("Direction", h, directionDampTime, Time.deltaTime);
}
}
}