测试项目的时候经常用到的控制摄像头运动,简单的移动转向
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour {
private GameObject gameObject;
float x1;
float x2;
float x3;
float x4;
void Start()
{
gameObject = GameObject.Find("Main Camera");
// Make the rigid body not change rotation
if (GetComponent<Rigidbody>())
GetComponent<Rigidbody>().freezeRotation = true;
}
// Update is called once per frame
void Update()
{
//空格键抬升高度
if (Input.GetKey(KeyCode.Space))
{
transform.position = new Vector3(transform.position.x, transform.position.y + 1, transform.position.z);
}
//w键前进
if (Input.GetKey(KeyCode.W))
{
this.gameObject.transform.Translate(new Vector3(0, 0, 50 * Time.deltaTime));
}