Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/DinoUI.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DinoUI.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/DinoUI.cs
-
curl -L -o DinoUI.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DinoUI.cs
1.79 kB
| using System.Text; | |
| using Fusion; | |
| using TMPro; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| public class DinoUI : MonoBehaviour | |
| { | |
| public TMP_Text aliveText; | |
| public TMP_Text itemText; | |
| public Text aliveTextLegacy; | |
| public Text itemTextLegacy; | |
| public float updateInterval = 0.25f; | |
| float nextUpdate; | |
| void Update() | |
| { | |
| if (Time.time < nextUpdate) | |
| return; | |
| nextUpdate = Time.time + updateInterval; | |
| DinoPlayer local = FindLocalPlayer(); | |
| DinoPlayer[] players = FindObjectsOfType<DinoPlayer>(); | |
| int alive = 0; | |
| foreach (DinoPlayer p in players) | |
| { | |
| if (p.IsAlive) | |
| alive++; | |
| } | |
| SetText(aliveText, aliveTextLegacy, $"Alive: {alive}"); | |
| if (local == null) | |
| { | |
| SetText(itemText, itemTextLegacy, "Item: -"); | |
| return; | |
| } | |
| string itemName = ItemName((ItemType)local.HeldItem); | |
| SetText(itemText, itemTextLegacy, $"Item: {itemName}"); | |
| } | |
| DinoPlayer FindLocalPlayer() | |
| { | |
| DinoPlayer[] players = FindObjectsOfType<DinoPlayer>(); | |
| foreach (DinoPlayer p in players) | |
| { | |
| if (p.Object != null && p.Object.HasInputAuthority) | |
| return p; | |
| } | |
| return null; | |
| } | |
| string ItemName(ItemType t) | |
| { | |
| switch (t) | |
| { | |
| case ItemType.Shield: return "Shield"; | |
| case ItemType.Speed: return "Speed"; | |
| case ItemType.Trap: return "Trap"; | |
| case ItemType.Projectile: return "Projectile"; | |
| default: return "-"; | |
| } | |
| } | |
| void SetText(TMP_Text tmp, Text legacy, string value) | |
| { | |
| if (tmp != null) tmp.text = value; | |
| if (legacy != null) legacy.text = value; | |
| } | |
| } | |