Skip to content

Commit

Permalink
fix end screen displaying for only one player
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyN3 committed Jan 11, 2022
1 parent 1071faf commit 25bfa47
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 130 deletions.
14 changes: 14 additions & 0 deletions Assets/Scenes/MapOne.unity
Original file line number Diff line number Diff line change
Expand Up @@ -9317,6 +9317,7 @@ GameObject:
- component: {fileID: 313140738}
- component: {fileID: 313140737}
- component: {fileID: 313140736}
- component: {fileID: 313140740}
m_Layer: 5
m_Name: Canvas_UI
m_TagString: Untagged
Expand Down Expand Up @@ -9407,6 +9408,19 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &313140740
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 313140735}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 15b9258afaf07ff4480514705e9c659e, type: 3}
m_Name:
m_EditorClassIdentifier:
endScreen: {fileID: 353577628}
--- !u!1 &321745481
GameObject:
m_ObjectHideFlags: 0
Expand Down
24 changes: 24 additions & 0 deletions Assets/Scripts/EndController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class EndController : MonoBehaviour
{
public GameObject endScreen;

void Awake()
{
if(endScreen == null)
{
endScreen = GameObject.Find("EndScreen");
}
endScreen.SetActive(false);
}

public void OnGameEnd(char winner)
{
endScreen.SetActive(true);
endScreen.transform.Find("Winner").GetComponent<TextMeshProUGUI>().text = winner == 'R' ? "Red Team" : "Blue Team";
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/EndController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions Assets/Scripts/Networking/NetworkingPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using BeardedManStudios.Forge.Networking.Generated;
using BeardedManStudios.Forge.Networking;
using BeardedManStudios.Forge.Networking.Unity;
using TMPro;

public class NetworkingPlayer : NetworkedPlayerBehavior
{
Expand All @@ -23,16 +22,13 @@ public class NetworkingPlayer : NetworkedPlayerBehavior
public GameObject model;
public Animator animator;

public GameObject endScreen;
public GameObject canvasController;

private IEnumerator Start()
{
while (networkObject == null) yield return null;

if(networkObject.IsOwner) {
endScreen = GameObject.Find("EndScreen");
endScreen.SetActive(false);
}

canvasController = GameObject.Find("Canvas_UI");
}

protected override void NetworkStart()
Expand Down Expand Up @@ -360,11 +356,13 @@ public override void TeamScore(RpcArgs args)

public override void EndGame(RpcArgs args)
{
GameObject endScreen = canvasController.GetComponent<EndController>().endScreen;

char winner = args.GetNext<char>();
endScreen.SetActive(true);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;

endScreen.transform.Find("Winner").GetComponent<TextMeshProUGUI>().text = winner == 'R' ? "Red Team" : "Blue Team";
canvasController.GetComponent<EndController>().OnGameEnd(winner);
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 25bfa47

Please sign in to comment.