Skip to content

Commit

Permalink
Fixed freecam acting up with more than 1 person
Browse files Browse the repository at this point in the history
  • Loading branch information
captnw committed Apr 2, 2022
1 parent 2f011c5 commit 7e9d481
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Colormancy/Assets/Scripts/UI/Camera/EnableFreeCam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ void Start()

private void Update()
{
if (!m_inFreeCamMode && Input.GetKey(KeyCode.O))
if (photonView.IsMine && !m_inFreeCamMode && Input.GetKey(KeyCode.O))
{
m_inFreeCamMode = true;
HandControlToFreeCam();
photonView.RPC("HandControlToFreeCam", PhotonNetwork.LocalPlayer);
}
}

Expand Down Expand Up @@ -90,10 +90,10 @@ public void HandControlFromFreeCam()
m_inFreeCamMode = false;
}

[PunRPC]
public void HandControlToFreeCam()
{
GameObject freeCam = Instantiate(m_freeCamPrefab);
freeCam.transform.position = transform.position;
GameObject freeCam = PhotonNetwork.Instantiate("Player/" + m_freeCamPrefab.name, transform.position, Quaternion.identity);
DontDestroyOnLoad(freeCam);
freeCam.GetComponent<FreeCam>().SetHumanForm(gameObject);
photonView.Owner.TagObject = freeCam;
Expand Down
14 changes: 9 additions & 5 deletions Colormancy/Assets/Scripts/UI/Camera/FreeCam.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Photon.Pun;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -22,7 +23,7 @@
///
/// This script is modified for usage in Photon.
/// </summary>
public class FreeCam : MonoBehaviour
public class FreeCam : MonoBehaviourPunCallbacks
{
/// <summary>
/// Normal speed of camera movement.
Expand Down Expand Up @@ -58,11 +59,13 @@ public class FreeCam : MonoBehaviour

void Update()
{
if (Input.GetKey(KeyCode.P))
if (photonView.IsMine && Input.GetKey(KeyCode.P))
{
// switch back to human form
//photonView.RPC("HandControlFromFreeCam", PhotonNetwork.LocalPlayer);

humanform.GetComponent<EnableFreeCam>().HandControlFromFreeCam();
Destroy(gameObject);
PhotonNetwork.Destroy(gameObject);
return;
}

Expand Down Expand Up @@ -134,9 +137,10 @@ void Update()
}
}

void OnDisable()
public override void OnDisable()
{
StopLooking();
base.OnDisable();
}

public void SetHumanForm(GameObject h)
Expand Down

0 comments on commit 7e9d481

Please sign in to comment.