Skip to content

Commit 86f1973

Browse files
committed
UI element to display who got killed.
1 parent a6718d3 commit 86f1973

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Scripts/UI/PlayerKilledUI.cs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using TMPro;
2+
using UnityEngine;
3+
4+
public class PlayerKilledUI : MonoBehaviour
5+
{
6+
[SerializeField] private CameraLogic cameraLogic;
7+
[SerializeField] private TextMeshProUGUI playerKilledText;
8+
[SerializeField] private GameObject panel;
9+
10+
void Start()
11+
{
12+
panel.SetActive(false);
13+
}
14+
15+
void Update()
16+
{
17+
HandlePlayerKillUI();
18+
}
19+
20+
private void HandlePlayerKillUI()
21+
{
22+
if (cameraLogic == null) return;
23+
24+
bool isPlayer1Assigned = cameraLogic.player1 != null;
25+
bool isPlayer2Assigned = cameraLogic.player2 != null;
26+
27+
if (!isPlayer1Assigned && !isPlayer2Assigned)
28+
{
29+
panel.SetActive(false);
30+
}
31+
else if (!isPlayer1Assigned)
32+
{
33+
panel.SetActive(true);
34+
SetPlayerKilledText("Player 1 Killed!");
35+
}
36+
else if (!isPlayer2Assigned)
37+
{
38+
panel.SetActive(true);
39+
SetPlayerKilledText("Player 2 Killed!");
40+
}
41+
else
42+
{
43+
panel.SetActive(false);
44+
}
45+
}
46+
47+
private void SetPlayerKilledText(string text)
48+
{
49+
playerKilledText.text = text;
50+
}
51+
}

0 commit comments

Comments
 (0)