unity 漫游相机
2017-12-15 本文已影响55人
繁木成林
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test_input : MonoBehaviour {
string message;
void Move(){
var inputMid = Input.GetKey (KeyCode.Mouse2);
var inputX = Input.GetAxis ("Mouse X");
var inputY = Input.GetAxis ("Mouse Y");
if (inputMid) {
this.transform.Translate(new Vector3 (0f, -inputY, 0f));
this.transform.Translate(new Vector3 (-inputX, 0f, 0f));
}
}
void ChangeRay(){
var inputX = Input.GetAxis ("Horizontal");
var inputY = Input.GetAxis ("Vertical");
this.transform.Rotate(new Vector3 (0f, inputX, 0f));
this.transform.Rotate(new Vector3 (-inputY, 0f, 0f));
}
void ChangeSize(){
var delteSize = Input.GetAxis ("Mouse ScrollWheel");
var Size = this.GetComponent<Camera> ().orthographicSize;
Size = Size -delteSize*10;
this.GetComponent<Camera> ().orthographicSize = Size;
}
void changeDis(){
var distance = Input.GetAxis ("Mouse ScrollWheel");
this.transform.position = this.transform.position + this.transform.rotation * new Vector3 (0f, 0f, distance*10.0f);
if (this.transform.position.y > 50.0f) {
this.GetComponent<Camera> ().orthographic = true;
}else {
this.GetComponent<Camera> ().orthographic = false;
}
}
void Update () {
Move ();
ChangeSize ();
ChangeRay ();
changeDis ();
message = Input.mousePosition.x + "," + Input.mousePosition.y + "," + Input.mousePosition.z;
}
void OnGUI(){
GUILayout.TextArea (message, 100);
}
}