Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/PushTrigger.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/PushTrigger.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/PushTrigger.cs
-
curl -L -o PushTrigger.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/PushTrigger.cs
1.28 kB
| using System.Collections.Generic; | |
| using Fusion; | |
| using UnityEngine; | |
| public class PushTrigger : NetworkBehaviour | |
| { | |
| public DinoPlayer owner; | |
| public float pushCooldown = 0.6f; | |
| public float zRange = 0.8f; | |
| readonly Dictionary<NetworkId, double> lastPushTime = new Dictionary<NetworkId, double>(); | |
| void Awake() | |
| { | |
| if (owner == null) | |
| owner = GetComponentInParent<DinoPlayer>(); | |
| } | |
| void OnTriggerStay(Collider other) | |
| { | |
| if (owner == null || !owner.Object.HasInputAuthority) | |
| return; | |
| DinoPlayer target = other.GetComponentInParent<DinoPlayer>(); | |
| if (target == null || target == owner) | |
| return; | |
| if (!owner.IsAlive || !target.IsAlive) | |
| return; | |
| if (Mathf.Abs(target.transform.position.z - owner.transform.position.z) > zRange) | |
| return; | |
| int dir = target.transform.position.x >= owner.transform.position.x ? 1 : -1; | |
| if (target.Object == null) | |
| return; | |
| double now = owner.Runner.SimulationTime; | |
| if (lastPushTime.TryGetValue(target.Object.Id, out double last) && (now - last) < pushCooldown) | |
| return; | |
| lastPushTime[target.Object.Id] = now; | |
| target.RpcRequestPush(dir); | |
| } | |
| } | |