天天看點

角色移動

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class move : MonoBehaviour

{

public float moveSpeed = 0.05f; //角色移動速度

private float h;

private float v;

private Vector3 dir;

private void Update()

{

PlayerMove();

}

void PlayerMove()

{

h = Input.GetAxis("Horizontal");

v = Input.GetAxis("Vertical");

dir = new Vector3(h, 0, v);

transform.LookAt(transform.position + dir); //角色朝向

2.1