Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/Obstacle.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 984 Bytes
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/Obstacle.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/Obstacle.cs
-
curl -L -o Obstacle.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/Obstacle.cs
984 Bytes
| using Fusion; | |
| using UnityEngine; | |
| public class Obstacle : NetworkBehaviour | |
| { | |
| public float despawnBehind = 15f; | |
| public override void FixedUpdateNetwork() | |
| { | |
| if (!Object.HasStateAuthority) | |
| return; | |
| float minZ = GetMinPlayerZ(); | |
| if (transform.position.z < minZ - despawnBehind) | |
| { | |
| Runner.Despawn(Object); | |
| } | |
| } | |
| void OnTriggerEnter(Collider other) | |
| { | |
| if (!Object.HasStateAuthority) | |
| return; | |
| DinoPlayer player = other.GetComponentInParent<DinoPlayer>(); | |
| if (player == null || !player.IsAlive) | |
| return; | |
| player.Kill(); | |
| } | |
| float GetMinPlayerZ() | |
| { | |
| DinoPlayer[] players = FindObjectsOfType<DinoPlayer>(); | |
| float minZ = transform.position.z; | |
| foreach (DinoPlayer p in players) | |
| { | |
| if (p.transform.position.z < minZ) | |
| minZ = p.transform.position.z; | |
| } | |
| return minZ; | |
| } | |
| } | |