Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/ItemBox.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/ItemBox.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/ItemBox.cs
-
curl -L -o ItemBox.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/ItemBox.cs
1.33 kB
| using Fusion; | |
| using UnityEngine; | |
| public class ItemBox : NetworkBehaviour | |
| { | |
| public ItemType[] items = new ItemType[] { | |
| ItemType.Shield, ItemType.Speed, ItemType.Trap, ItemType.Projectile | |
| }; | |
| public GameObject breakEffectPrefab; | |
| public float breakEffectLife = 1.2f; | |
| public override void Spawned() | |
| { | |
| if (items == null || items.Length == 0) | |
| items = new ItemType[] { ItemType.Shield, ItemType.Speed }; | |
| } | |
| void OnTriggerEnter(Collider other) | |
| { | |
| if (!Object.HasStateAuthority) | |
| return; | |
| DinoPlayer player = other.GetComponentInParent<DinoPlayer>(); | |
| if (player == null || !player.IsAlive) | |
| return; | |
| if (player.HeldItem != 0) | |
| return; | |
| ItemType picked = items[Random.Range(0, items.Length)]; | |
| player.GiveItem(picked); | |
| RpcBreakEffect(transform.position); | |
| Runner.Despawn(Object); | |
| } | |
| [] | |
| void RpcBreakEffect(Vector3 pos) | |
| { | |
| if (breakEffectPrefab == null) | |
| return; | |
| GameObject fx = Instantiate(breakEffectPrefab, pos, Quaternion.identity); | |
| Destroy(fx, breakEffectLife); | |
| DinoAudio audio = DinoAudio.Instance; | |
| if (audio != null) | |
| audio.PlayBoxBreak(); | |
| } | |
| } | |