Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/DroppingObstacle.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DroppingObstacle.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/DroppingObstacle.cs
-
curl -L -o DroppingObstacle.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DroppingObstacle.cs
1.54 kB
| using Fusion; | |
| using UnityEngine; | |
| public class DroppingObstacle : NetworkBehaviour | |
| { | |
| public float triggerZRange = 4f; | |
| public float dropSpeed = 10f; | |
| public float dropDistance = 3f; | |
| public float resetDelay = 2.5f; | |
| Vector3 startPos; | |
| [] public NetworkBool IsDropping { get; set; } | |
| [] public TickTimer ResetTimer { get; set; } | |
| public override void Spawned() | |
| { | |
| startPos = transform.position; | |
| } | |
| public override void FixedUpdateNetwork() | |
| { | |
| if (!Object.HasStateAuthority) | |
| return; | |
| if (!IsDropping) | |
| { | |
| if (PlayerInRange()) | |
| IsDropping = true; | |
| return; | |
| } | |
| Vector3 pos = transform.position; | |
| pos.y -= dropSpeed * Runner.DeltaTime; | |
| transform.position = pos; | |
| if (pos.y <= startPos.y - dropDistance) | |
| { | |
| if (!ResetTimer.IsRunning) | |
| ResetTimer = TickTimer.CreateFromSeconds(Runner, resetDelay); | |
| } | |
| if (ResetTimer.Expired(Runner)) | |
| { | |
| transform.position = startPos; | |
| IsDropping = false; | |
| } | |
| } | |
| bool PlayerInRange() | |
| { | |
| DinoPlayer[] players = FindObjectsOfType<DinoPlayer>(); | |
| foreach (DinoPlayer p in players) | |
| { | |
| if (!p.IsAlive) | |
| continue; | |
| float dz = Mathf.Abs(p.transform.position.z - transform.position.z); | |
| if (dz <= triggerZRange) | |
| return true; | |
| } | |
| return false; | |
| } | |
| } | |