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/GuardCamera.cs

57 lines
1.6 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GuardCamera : Photon.PunBehaviour {
public float xRotation = 0.0f;
public float yRotation = 0.0f;
2017-09-21 06:48:52 -05:00
public bool laserSightEnabled = false;
private GameObject line;
void Start () {
xRotation = transform.eulerAngles.y;
yRotation = transform.eulerAngles.x;
}
void Update () {
2017-09-21 06:48:52 -05:00
Quaternion newRotation = Quaternion.AngleAxis(xRotation, Vector3.up);
newRotation *= Quaternion.AngleAxis(-yRotation, -Vector3.right);
transform.localRotation = Quaternion.Slerp(transform.rotation, newRotation, Time.time * 0.01f);
if (laserSightEnabled)
{
if (line == null)
line = LineDrawer.MakeLine();
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit))
LineDrawer.DrawLine(line, transform.position, hit.point);
else
LineDrawer.DrawLine(line, transform.position, transform.position + transform.forward * 20.0f);
}
else
{
if (line != null)
Destroy(line);
}
}
public void UpdateRotation()
{
photonView.RPC("UpdateRotation", PhotonTargets.All, xRotation, yRotation);
}
[PunRPC]
void UpdateRotation(float xRotation, float yRotation)
{
this.xRotation = xRotation;
this.yRotation = yRotation;
}
2017-09-21 06:48:52 -05:00
[PunRPC]
void SetEnabledRPC(bool enabled)
{
laserSightEnabled = enabled;
}
}