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/Mouse Control/Assets/MouseController.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
191 lines (158 sloc)
4.64 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 MouseController : MonoBehaviour | |
{ | |
//Camera Variables | |
GameObject cameraSet; | |
public Camera camera0; | |
public Camera camera1; | |
public Camera camera2; | |
public Camera camera3; | |
public Camera camera4; | |
//Camera States | |
int room = 0; | |
//Counter Variables | |
public int holdKey1 = 0; | |
public int holdKey2 = 0; | |
public int openLock1 = 0; | |
public int openLock2 = 0; | |
Ray ray; | |
RaycastHit hit; | |
public GameObject prefab; | |
void Start() | |
{ | |
camera0.enabled = true; | |
camera1.enabled = false; | |
camera2.enabled = false; | |
camera3.enabled = false; | |
camera4.enabled = false; | |
room = 0; | |
} | |
void Update () | |
{ | |
//ray = Camera.main.ScreenPointToRay (Input.mousePosition); | |
//Clicking | |
if (Physics.Raycast (ray, out hit)) { | |
if (Input.GetKeyDown (KeyCode.Mouse0)) { | |
if (hit.transform.name == "Key1") | |
{ | |
Debug.Log("Left Mouse Down"); | |
Destroy(hit.transform.gameObject); | |
holdKey1 = 1; | |
Debug.Log(holdKey1.ToString()); | |
} | |
if (hit.transform.name == "Key2") | |
{ | |
Debug.Log("Left Mouse Down"); | |
Debug.Log(holdKey2.ToString()); | |
Destroy(hit.transform.gameObject); | |
holdKey2 = 1; | |
Debug.Log(holdKey2.ToString()); | |
} | |
if (hit.transform.name == "Lock1") | |
{ | |
if (holdKey1 == 1) | |
{ | |
Destroy(hit.transform.gameObject); | |
openLock1 = 1; | |
} | |
} | |
if (hit.transform.name == "Lock2") | |
{ | |
if (holdKey2 == 1) | |
{ | |
Destroy(hit.transform.gameObject); | |
openLock2 = 1; | |
} | |
} | |
//GameObject obj = Instantiate (prefab, new Vector3 (hit.point.x, hit.point.y, hit.point.z), Quaternion.identity) as GameObject; | |
} | |
if (Input.GetKeyDown (KeyCode.Mouse1)) { | |
Debug.Log ("Righ Mouse Down"); | |
Destroy(hit.transform.gameObject); | |
} | |
} | |
//Moving | |
//Room 0, Entrance | |
if (room == 0) | |
{ | |
camera1.enabled = false; | |
camera2.enabled = false; | |
camera3.enabled = false; | |
camera4.enabled = false; | |
camera0.enabled = true; | |
ray = camera0.ScreenPointToRay(Input.mousePosition); | |
if (Input.GetKeyDown(KeyCode.W)) | |
{ | |
room = 1; | |
} | |
} | |
//Room 1, Middle | |
if (room == 1) | |
{ | |
camera0.enabled = false; | |
camera2.enabled = false; | |
camera3.enabled = false; | |
camera4.enabled = false; | |
camera1.enabled = true; | |
ray = camera1.ScreenPointToRay(Input.mousePosition); | |
//Check the Lock | |
if (Input.GetKeyDown(KeyCode.A)) | |
{ | |
room = 3; | |
} | |
if (Input.GetKeyDown(KeyCode.D)) | |
{ | |
room = 4; | |
} | |
if (Input.GetKeyDown(KeyCode.S)) | |
{ | |
room = 0; | |
} | |
if (Input.GetKeyDown(KeyCode.W)) | |
{ | |
if (openLock1 + openLock2 == 2) | |
room = 2; | |
} | |
} | |
//Room 2, End | |
if (room == 2) | |
{ | |
camera0.enabled = false; | |
camera1.enabled = false; | |
camera3.enabled = false; | |
camera4.enabled = false; | |
camera2.enabled = true; | |
ray = camera2.ScreenPointToRay(Input.mousePosition); | |
} | |
//Room 3, Left | |
if (room == 3) | |
{ | |
camera0.enabled = false; | |
camera2.enabled = false; | |
camera1.enabled = false; | |
camera4.enabled = false; | |
camera3.enabled = true; | |
ray = camera3.ScreenPointToRay(Input.mousePosition); | |
if (Input.GetKeyDown(KeyCode.D)) | |
{ | |
room = 1; | |
} | |
} | |
//Room 4, Right | |
if (room == 4) | |
{ | |
camera0.enabled = false; | |
camera2.enabled = false; | |
camera1.enabled = false; | |
camera3.enabled = false; | |
camera4.enabled = true; | |
ray = camera4.ScreenPointToRay(Input.mousePosition); | |
if (Input.GetKeyDown(KeyCode.A)) | |
{ | |
room = 1; | |
} | |
} | |
} | |
} |