Unity全视角游戏的键盘操作位移——研究笔记

时间:2022-06-23 17:18:47
 using UnityEngine;
using System.Collections; public class MoveCeShi : MonoBehaviour
{
public float m_Speed = ; private CharacterController m_cc; void Start ()
{
m_cc = this.GetComponent<CharacterController>();
} void Update ()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if (Mathf.Abs(h) > 0.05f || Mathf.Abs(v) > 0.05f)
{
var dir = new Vector3(h, v, );
Rotate(dir);
Move();
} }
void Move()
{ m_cc.SimpleMove(this.transform.forward * m_Speed);
} void Rotate(Vector3 Dir)
{
Vector3 ScreenPos = Camera.main.WorldToScreenPoint(this.transform.position);
Vector3 DestPoint = ScreenPos + Dir*;
Vector3 WorldPos = Camera.main.ScreenToWorldPoint(DestPoint);
var tagetPos = new Vector3(WorldPos.x, this.transform.position.y, WorldPos.z);
this.transform.LookAt(tagetPos); }
}