2017-09-18 11:10:49 -05:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2017-09-21 04:59:13 -05:00
|
|
|
|
public class GuardCameraController : Photon.PunBehaviour {
|
2017-09-18 11:10:49 -05:00
|
|
|
|
|
|
|
|
|
private float camSens = 120.0f;
|
2017-09-21 04:59:13 -05:00
|
|
|
|
private GuardCamera cam;
|
|
|
|
|
|
|
|
|
|
static List<GuardCameraController> cameras;
|
|
|
|
|
static int currentCamera;
|
2017-09-18 11:10:49 -05:00
|
|
|
|
|
|
|
|
|
void Start () {
|
2017-09-21 04:59:13 -05:00
|
|
|
|
cam = GetComponent<GuardCamera>();
|
|
|
|
|
if (cameras == null)
|
|
|
|
|
{
|
|
|
|
|
cameras = new List<GuardCameraController>();
|
|
|
|
|
foreach (var camera in GameObject.FindGameObjectsWithTag(tag))
|
|
|
|
|
{
|
|
|
|
|
cameras.Add(camera.GetComponent<GuardCameraController>());
|
|
|
|
|
}
|
|
|
|
|
for (int i=0; i < cameras.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (cameras[i] == this)
|
|
|
|
|
currentCamera = i;
|
|
|
|
|
else
|
|
|
|
|
SetCameraEnabled(cameras[i], false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GuardCameraController GetCurrentCamera()
|
|
|
|
|
{
|
|
|
|
|
return cameras[currentCamera];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GuardCameraController GetNextCamera(out int nextCameraPos)
|
|
|
|
|
{
|
|
|
|
|
nextCameraPos = (currentCamera + 1) % cameras.Count;
|
|
|
|
|
return cameras[nextCameraPos];
|
|
|
|
|
}
|
2017-09-18 11:10:49 -05:00
|
|
|
|
|
2017-09-21 04:59:13 -05:00
|
|
|
|
void SwitchCamera()
|
|
|
|
|
{
|
|
|
|
|
var nextCam = GetNextCamera(out currentCamera);
|
|
|
|
|
SetCameraEnabled(nextCam, true);
|
|
|
|
|
SetCameraEnabled(this, false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-21 06:48:52 -05:00
|
|
|
|
public void SetCameraEnabled(GuardCameraController gCamera, bool enabled)
|
2017-09-21 04:59:13 -05:00
|
|
|
|
{
|
2017-09-21 06:48:52 -05:00
|
|
|
|
gCamera.GetComponent<Camera>().enabled = enabled;
|
|
|
|
|
gCamera.GetComponent<AudioListener>().enabled = enabled;
|
|
|
|
|
gCamera.enabled = enabled;
|
|
|
|
|
gCamera.photonView.RPC("SetEnabledRPC", PhotonTargets.Others, enabled);
|
2017-09-21 04:59:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 11:10:49 -05:00
|
|
|
|
void Update () {
|
2017-09-21 04:59:13 -05:00
|
|
|
|
if (Input.GetKeyDown("space"))
|
|
|
|
|
SwitchCamera();
|
|
|
|
|
|
|
|
|
|
RaycastHit hit;
|
|
|
|
|
if (Input.GetButtonDown("Fire1"))
|
|
|
|
|
{
|
|
|
|
|
Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
|
|
|
|
|
|
|
|
|
|
if (Physics.Raycast(ray, out hit, 100.0f))
|
|
|
|
|
{
|
2017-09-28 13:36:17 -05:00
|
|
|
|
if (hit.transform.gameObject.tag == "NPC")
|
2017-09-21 04:59:13 -05:00
|
|
|
|
{
|
|
|
|
|
var manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
|
|
|
|
|
manager.photonView.RPC("ShowSpiesWinScreen", PhotonTargets.All);
|
|
|
|
|
}
|
2017-09-28 13:36:17 -05:00
|
|
|
|
else if (hit.transform.gameObject.tag == "Spy")
|
2017-09-21 04:59:13 -05:00
|
|
|
|
{
|
|
|
|
|
var manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
|
|
|
|
|
manager.photonView.RPC("ShowGuardsWinScreen", PhotonTargets.All);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cam.xRotation += Time.deltaTime * Input.GetAxis("Horizontal") * camSens;
|
|
|
|
|
cam.yRotation += Time.deltaTime * -Input.GetAxis("Vertical") * camSens;
|
|
|
|
|
cam.xRotation = cam.xRotation % 360;
|
|
|
|
|
cam.yRotation = Mathf.Clamp(cam.yRotation, -45, 80);
|
|
|
|
|
cam.UpdateRotation();
|
2017-09-18 11:10:49 -05:00
|
|
|
|
}
|
|
|
|
|
}
|