﻿/*
 摄像机 的控制类 
 通过键盘控制摄像机的上下左右前后移动
 *(1)空格键重置摄像机的位置
 *(2)Q键抬升摄像机高度
 *(3)E键降低摄像机高度
 *(4)W键摄像机前进
 *(5)S键摄像机后退
 *(6)A键摄像机左移
 *(7)D键摄像机右移
 */
using UnityEngine;
 
public class cameraCtl : MonoBehaviour {
    // Use this for initialization
    private GameObject cameraObject;

    float x1;
	float x2;
	float x3;
	float x4;
	void Start () {
        cameraObject = gameObject;
        /*这里的主摄像机名必须是Main Camera
         摄像机起始位置 0,2,3.5
         摄像机初始旋转角度15,180,0
         */
	}
	
	// Update is called once per frame
	void Update () {
        //空格键重置摄像机的位置
        if (Input.GetKey(KeyCode.Space))
        {
            this.cameraObject.transform.position = new Vector3(0, 2, 3.5f);
        }
		//Q键抬升摄像机高度
		if (Input.GetKey (KeyCode.Q))
		{
			transform.position =  new Vector3(transform.position.x,transform.position.y + 0.25f,transform.position.z);
		}
        //E键降低摄像机高度
        if (Input.GetKey(KeyCode.E))
        {
            transform.position = new Vector3(transform.position.x, transform.position.y -0.25f, transform.position.z);
        }
        //W键摄像机前进
		if(Input.GetKey(KeyCode.W))
		{
			this.cameraObject.transform.Translate(new Vector3(0,0,5.0f*Time.deltaTime));
		}
        //S键摄像机后退
		if(Input.GetKey(KeyCode.S))
		{
			this.cameraObject.transform.Translate(new Vector3(0,0,-5.0f*Time.deltaTime));
		}
        //A键摄像机左移
		if(Input.GetKey(KeyCode.A))
		{
			this.cameraObject.transform.Translate(new Vector3(-0.25f,0,0*Time.deltaTime));
		}
        //D键摄像机右移
		if(Input.GetKey(KeyCode.D))
		{
			this.cameraObject.transform.Translate(new Vector3(0.25f,0,0*Time.deltaTime));
		}
	}
}
