//控制人物wasd移动,加到刚性物体或者摄像头
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MOVE : MonoBehaviour {
int MoveSpeed = 16;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W))
{
this.transform.Translate(Vector3.forward * Time.deltaTime * MoveSpeed);
}
if (Input.GetKey(KeyCode.S))
{
this.transform.Translate(Vector3.back * Time.deltaTime * MoveSpeed);
}
if (Input.GetKey(KeyCode.A))
{
this.transform.Translate(Vector3.left * Time.deltaTime * MoveSpeed);
}
if (Input.GetKey(KeyCode.D))
{
this.transform.Translate(Vector3.right * Time.deltaTime * MoveSpeed);
}
}
}
//控制摄像头旋转加到摄像头上
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class xuanzhuan : MonoBehaviour {
public float moveSpeed;
void Start()
{
moveSpeed = 60f; //移动速度
}
void Update()
{
Vector3 angle = Vector3.zero;
angle.x = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * moveSpeed * Time.deltaTime;
angle.y = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * moveSpeed * Time.deltaTime;
transform.localEulerAngles = angle;
}
}