Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Intro_Scritping/Test_CYOA/Assets/Scripts/Camera_Control.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
282 lines (246 sloc)
7.63 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Camera_Control : MonoBehaviour { | |
//Mouse-Camera Controlls | |
public Ray ray; | |
public RaycastHit hit; | |
Quaternion rot = new Quaternion(); | |
//public float camAngleX = 0f; | |
public float camAngleY = 0f; | |
//public float camAngleZ = 0f; | |
//PoV Camera | |
public Camera mainCam; | |
//Camera Rotate Tests | |
public float tiltAngle = 30.0f; | |
public Vector3 cameraAngle = new Vector3 (0f,0f,0f); | |
//Camera Position | |
public int cameraPos; | |
public GameObject loc1; | |
public GameObject loc2; | |
public GameObject loc3; | |
public GameObject loc4; | |
public GameObject loc5; | |
public GameObject loc6; | |
public GameObject loc7; | |
public GameObject loc8; | |
public GameObject loc9; | |
public GameObject loc10; | |
public GameObject loc11; | |
//Camera Positions | |
public Vector3 pos1 = new Vector3(0f, 0f, -5.0f); | |
public Vector3 pos2 = new Vector3(0f, 0f, 12.0f); | |
public Vector3 pos3 = new Vector3(0f, 0f, 19.0f); | |
public Vector3 pos4 = new Vector3(1.0f, 0f, 35.0f); | |
public Vector3 pos5 = new Vector3(17.0f, 0f, 35.0f); | |
public Vector3 pos6 = new Vector3(15.0f, 0f, 20.0f); | |
public Vector3 pos7 = new Vector3(-18.0f, 0f, 18.0f); | |
public Vector3 pos8 = new Vector3(-20.0f, 0f, 3.0f); | |
public Vector3 pos9 = new Vector3(-31.0f, 0f, 12.0f); | |
public Vector3 pos10 = new Vector3(-31.0f, 0f, 0.0f); | |
public Vector3 pos11 = new Vector3(16.0f, 0f, 16.0f); | |
//Camera Angles - Start | |
public Vector3 ang1 = new Vector3(0f, 0f, 0f); | |
public Vector3 ang4 = new Vector3(0f, 150.0f, 0f); | |
public Vector3 ang5 = new Vector3(0f, -130.0f, 0f); | |
public Vector3 ang6 = new Vector3(0f, -45.0f, 0f); | |
public Vector3 ang7 = new Vector3(0f, -90.0f, 0f); | |
// Use this for initialization | |
void Start () | |
{ | |
//establish Main Camera | |
mainCam = Camera.main; | |
cameraPos = 1; | |
ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
cameraAngle = new Vector3 (0.0f, camAngleY, 0.0f); | |
ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
//Camera Move Mouse Clicks | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos1") | |
{ | |
cameraPos = 1; | |
rot.eulerAngles = ang1; | |
transform.rotation = rot; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos2") | |
{ | |
cameraPos = 2; | |
Debug.Log("Click Registered"); | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos3") | |
{ | |
cameraPos = 3; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos4") | |
{ | |
cameraPos = 4; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos5") | |
{ | |
cameraPos = 5; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos6") | |
{ | |
cameraPos = 6; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos7") | |
{ | |
cameraPos = 7; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos8") | |
{ | |
cameraPos = 8; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos9") | |
{ | |
cameraPos = 9; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos10") | |
{ | |
cameraPos = 10; | |
} | |
} | |
} | |
if (Physics.Raycast(ray, out hit)) | |
{ | |
if (Input.GetKeyDown(KeyCode.Mouse0)) | |
{ | |
if (hit.transform.name == "PlayerPos11") | |
{ | |
cameraPos = 11; | |
} | |
} | |
} | |
//Camera Angle Movement | |
float tiltAroundZ = Input.GetAxis ("Horizontal") * tiltAngle; | |
// if (Input.GetKeyDown(KeyCode.H)) | |
// { | |
// Debug.Log ("H Pressed"); | |
// Quaternion target = Quaternion.Euler (0, 0, tiltAroundZ); | |
// transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 2.0f); | |
// } | |
// | |
var camRot = Quaternion.Euler(Camera.main.transform.eulerAngles); | |
//mainCam.transform.rotation = cameraAngle; | |
if(Input.GetKeyDown(KeyCode.H)) | |
{ | |
//camAngleY = camAngleY + 90; | |
//mainCam.transform.rotation = Quaternion.AngleAxis(90,camRot); | |
//Debug.Log ("H button pushed"); | |
//Camera.main.transform.Rotate = (Vector3.right * Time.deltaTime); | |
} | |
//Camera Move Switch Statement | |
switch (cameraPos) | |
{ | |
case 1: | |
mainCam.transform.position = pos1; | |
rot.eulerAngles = ang1; | |
mainCam.transform.rotation = rot; | |
//mainCam; | |
break; | |
case 2: | |
mainCam.transform.position = pos2; | |
break; | |
case 3: | |
mainCam.transform.position = pos3; | |
break; | |
case 4: | |
mainCam.transform.position = pos4; | |
rot.eulerAngles = ang4; | |
transform.rotation = rot; | |
break; | |
case 5: | |
mainCam.transform.position = pos5; | |
rot.eulerAngles = ang5; | |
transform.rotation = rot; | |
break; | |
case 6: | |
mainCam.transform.position = pos6; | |
rot.eulerAngles = ang6; | |
transform.rotation = rot; | |
break; | |
case 7: | |
mainCam.transform.position = pos7; | |
rot.eulerAngles = ang7; | |
mainCam.transform.rotation = rot; | |
break; | |
case 8: | |
mainCam.transform.position = pos8; | |
break; | |
case 9: | |
mainCam.transform.position = pos9; | |
break; | |
case 10: | |
mainCam.transform.position = pos10; | |
break; | |
case 11: | |
mainCam.transform.position = pos11; | |
break; | |
default: | |
mainCam.transform.position = pos1; | |
rot.eulerAngles = ang1; | |
mainCam.transform.rotation = rot; | |
break; | |
} | |
} | |
} |