代码如下:
using UnityEngine;
public class CameraController : MonoBehaviour {
private Camera _Camera;
private bool _IsLeft= false;
private bool _IsRight= false;
// Use this for initialization
void Start () {
_Camera = Camera.main;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A))//向左看
{
_IsLeft = true;
}
if (Input.GetKeyUp(KeyCode.A))
{
_IsLeft = false;
}
if (Input.GetKeyDown(KeyCode.D))//向左看
{
_IsRight = true;
}
if (Input.GetKeyUp(KeyCode.D))
{
_IsRight = false;
}
if (_IsLeft)
{
transform.Rotate(transform.rotation.x,Time.deltaTime * -100, transform.rotation.z);
}
if (_IsRight)
{
transform.Rotate(transform.rotation.x, Time.deltaTime * 100, transform.rotation.z);
}
}
}