Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class FlashlightController : Photon.MonoBehaviour, INetworkHandler {
- public GameObject flashlight;
- public KeyCode toggleFlashlight = KeyCode.F;
- void OnEnable() {
- GetComponent<NetworkSerializationHandler>().Hook(this);
- }
- void OnDisable() {
- GetComponent<NetworkSerializationHandler>().Unhook(this);
- }
- void Update() {
- if(photonView.isMine) {
- if(Input.GetKeyDown(toggleFlashlight))
- flashlight.SetActive(!flashlight.activeSelf);
- RaycastHit hit;
- if(flashlight.activeSelf && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
- flashlight.transform.LookAt(hit.point);
- else
- flashlight.transform.localRotation = Quaternion.identity;
- }
- }
- public void OnNetworkWrite(PhotonStream stream, PhotonMessageInfo info) {
- stream.SendNext(flashlight.activeSelf);
- stream.SendNext(flashlight.transform.rotation);
- }
- public void OnNetworkRead(PhotonStream stream, PhotonMessageInfo info) {
- flashlight.SetActive((bool)stream.ReceiveNext());
- flashlight.transform.rotation = (Quaternion)stream.ReceiveNext();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment