This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
project-undercover/Project Undercover/Assets/Scripts/Guard/GuardCameraController.cs

91 lines
2.9 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GuardCameraController : Photon.PunBehaviour {
private float camSens = 120.0f;
private GuardCamera cam;
static List<GuardCameraController> cameras;
static int currentCamera;
void Start () {
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];
}
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 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);
}
void Update () {
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")
{
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")
{
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();
}
}