Commit 34572d18 by alsunj

remove unnecessary calls in chest script

parent 9573686b
Showing with 12 additions and 32 deletions
...@@ -7,19 +7,8 @@ public class Chest : NetworkBehaviour, IInteractable ...@@ -7,19 +7,8 @@ public class Chest : NetworkBehaviour, IInteractable
{ {
private GameObject _chestLid; private GameObject _chestLid;
private bool _chestFound; private NetworkVariable<bool> _chestFound = new NetworkVariable<bool>(false);
[ServerRpc(RequireOwnership = false)]
private void CmdOpenChestForEveryoneServerRpc()
{
RpcOpenChestForEveryoneClientRpc();
}
[ClientRpc]
private void RpcOpenChestForEveryoneClientRpc()
{
Interacted();
}
private void Awake() private void Awake()
{ {
...@@ -30,15 +19,18 @@ public class Chest : NetworkBehaviour, IInteractable ...@@ -30,15 +19,18 @@ public class Chest : NetworkBehaviour, IInteractable
} }
} }
private void ChestFound() [ServerRpc(RequireOwnership = false)]
private void ChestFoundServerRpc()
{ {
_chestLid.transform.DORotate(_chestLid.transform.eulerAngles + if (!_chestFound.Value)
new Vector3(-130, 0, 0), 1f) {
.SetEase(Ease.OutBounce); ChestFoundClientRpc();
CmdOpenChestForEveryoneServerRpc(); _chestFound.Value = true;
}
} }
private void ChestFoundForOtherClients() [ClientRpc]
private void ChestFoundClientRpc()
{ {
_chestLid.transform.DORotate(_chestLid.transform.eulerAngles + _chestLid.transform.DORotate(_chestLid.transform.eulerAngles +
new Vector3(-130, 0, 0), 1f) new Vector3(-130, 0, 0), 1f)
...@@ -48,19 +40,6 @@ public class Chest : NetworkBehaviour, IInteractable ...@@ -48,19 +40,6 @@ public class Chest : NetworkBehaviour, IInteractable
public void Interact() public void Interact()
{ {
if (!_chestFound) ChestFoundServerRpc();
{
ChestFound();
_chestFound = true;
}
}
public void Interacted()
{
if (!_chestFound)
{
ChestFoundForOtherClients();
_chestFound = true;
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment