Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Rotator : MonoBehaviour {
- public Transform sopwith;
- public Transform fokker;
- public Light keyLight;
- public float sensitivity;
- private Transform thisTransform;
- private Vector3 previousMousePos;
- private Vector3 deltaPos;
- private float cameraDistance;
- private float keyLightStrength;
- private bool overGUI;
- private Rect sliderRect;
- // private bool changingLightStrength;
- void Awake () {
- thisTransform = sopwith;
- fokker.gameObject.SetActiveRecursively (false);
- cameraDistance = 75.0f;
- keyLightStrength = 1.0f;
- sliderRect = new Rect((Screen.width/2) - 100, 25, 200, 75);
- // changingLightStrength = false;
- }
- void OnGUI () {
- GUILayout.BeginArea (new Rect(25, 25, 80, 200));
- // GUILayout.BeginVertical ();
- if (GUILayout.Button ("Sopwith")) {
- thisTransform = sopwith;
- // thisTransform.eulerAngles = Vector3.zero;
- sopwith.gameObject.SetActiveRecursively (true);
- fokker.gameObject.SetActiveRecursively (false);
- }
- if (GUILayout.Button ("Fokker")) {
- thisTransform = fokker;
- // thisTransform.eulerAngles = Vector3.zero;
- fokker.gameObject.SetActiveRecursively (true);
- sopwith.gameObject.SetActiveRecursively (false);
- }
- if (GUILayout.Button ("Reset")) {
- thisTransform.eulerAngles = Vector3.zero;
- }
- // GUILayout.EndVertical ();
- GUILayout.EndArea ();
- GUILayout.BeginArea (sliderRect);
- GUILayout.BeginHorizontal ();
- GUILayout.Label ("0", GUILayout.MaxWidth(10));
- keyLightStrength = GUILayout.HorizontalSlider (keyLightStrength, 0.0f, 1.0f);
- GUILayout.Label ("1", GUILayout.MaxWidth(10));
- keyLight.intensity = keyLightStrength;
- GUILayout.EndHorizontal ();
- GUILayout.Label ("Key Light Intensity: " + keyLight.intensity);
- GUILayout.EndArea ();
- GUILayout.BeginArea (new Rect(Screen.width - 105, 25, 80, 200));
- if (GUILayout.Button ("Close View")) cameraDistance = 75;
- if (GUILayout.Button ("RR1")) cameraDistance = 150;
- if (GUILayout.Button ("RR2")) cameraDistance = 300;
- if (GUILayout.Button ("RR3")) cameraDistance = 450;
- if (GUILayout.Button ("RR4")) cameraDistance = 600;
- Vector3 newPosition = Vector3.zero;
- newPosition.z = cameraDistance;
- Camera.main.transform.position = newPosition;
- GUILayout.EndArea ();
- if (sliderRect.Contains (Input.mousePosition)) {
- // if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
- // overGUI = true;
- // Debug.Log ("Over GUI");
- } else {
- overGUI = false;
- // Debug.Log ("NOT Over GUI");
- }
- if (sliderRect.Contains (Event.current.mousePosition)) {
- // if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
- overGUI = true;
- // Debug.Log ("Over GUI");
- } else {
- overGUI = false;
- // Debug.Log ("NOT Over GUI");
- }
- Debug.Log ("-----Event.current.mousePosition: " + Event.current.mousePosition);
- // Rect guiRect = GUILayoutUtility.GetLastRect();
- // if (Event.current != null && Event.current.isMouse) {
- // if (Event.current != null && Event.current.type == EventType.Repaint && Event.current.isMouse) {
- // overGUI = sliderRect.Contains(Input.mousePosition);
- // Debug.Log (overGUI);
- // }
- }
- void Update () {
- if (!overGUI) {
- // if (sliderRect.Contains (Input.mousePosition)) {
- //// if (Input.GetMouseButton(0) && sliderRect.Contains (Input.mousePosition)) {
- // Debug.Log ("Over GUI");
- // } else {
- // Debug.Log ("NOT Over GUI");
- if (Input.GetMouseButtonDown(0)) {
- previousMousePos = Input.mousePosition;
- } else {
- deltaPos = Vector3.zero;
- }
- if (Input.GetMouseButton(0)) {
- deltaPos = Input.mousePosition - previousMousePos;
- previousMousePos = Input.mousePosition;
- Vector3 newRotation = Vector3.zero;
- newRotation.x = -deltaPos.y * sensitivity;
- newRotation.y = -deltaPos.x * sensitivity;
- thisTransform.Rotate (newRotation, Space.World);
- }
- }
- Debug.Log ("Input.mousePosition: " + Input.mousePosition);
- // if (!overGUI) {
- // if (Input.GetMouseButtonDown(0)) {
- // previousMousePos = Input.mousePosition;
- // } else {
- // deltaPos = Vector3.zero;
- // }
- //
- // if (Input.GetMouseButton(0)) {
- // deltaPos = Input.mousePosition - previousMousePos;
- // previousMousePos = Input.mousePosition;
- // Vector3 newRotation = Vector3.zero;
- // newRotation.x = -deltaPos.y * sensitivity;
- // newRotation.y = -deltaPos.x * sensitivity;
- // thisTransform.Rotate (newRotation, Space.World);
- // }
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement