PlayerMove脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum State
{
Idle,
Walk
}
public class PlayerMove : MonoBehaviour
{
public float speed = 1;
private PlayerDir dir;
private CharacterController controller;
public State playerState;
public bool isMoving = false;
// Start is called before the first frame update
void Start()
{
dir = this.transform.GetComponent<PlayerDir>();
controller = this.GetComponent<CharacterController>();
playerState = State.Idle;
}
// Update is called once per frame
void Update()
{
float distance = Vector3.Distance(dir.TargetPosition, transform.position);
if (distance > 0.3f)
{
isMoving = true;
controller.SimpleMove(transform.forward * speed);
playerState = State.Walk;
}
else
{
isMoving = false;
playerState = State.Idle;
}
}
}
PlayerDir玩家朝向问题
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerDir : MonoBehaviour
{
public GameObject effect_Click;
// Start is called before the first frame update
private