Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/ItemProjectile.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/ItemProjectile.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/ItemProjectile.cs
-
curl -L -o ItemProjectile.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/ItemProjectile.cs
1.42 kB
| using Fusion; | |
| using UnityEngine; | |
| public class ItemProjectile : NetworkBehaviour | |
| { | |
| public float speed = 12f; | |
| public float lifeSeconds = 2f; | |
| [] public NetworkId OwnerId { get; set; } | |
| [] public TickTimer LifeTimer { get; set; } | |
| public override void Spawned() | |
| { | |
| if (Object.HasStateAuthority) | |
| LifeTimer = TickTimer.CreateFromSeconds(Runner, lifeSeconds); | |
| } | |
| public void SetOwner(NetworkId ownerId) | |
| { | |
| if (!Object.HasStateAuthority) | |
| return; | |
| OwnerId = ownerId; | |
| } | |
| public override void FixedUpdateNetwork() | |
| { | |
| if (Object.HasStateAuthority) | |
| { | |
| if (LifeTimer.Expired(Runner)) | |
| { | |
| Runner.Despawn(Object); | |
| return; | |
| } | |
| transform.position += transform.forward * speed * Runner.DeltaTime; | |
| } | |
| } | |
| void OnTriggerEnter(Collider other) | |
| { | |
| if (!Object.HasStateAuthority) | |
| return; | |
| DinoPlayer target = other.GetComponentInParent<DinoPlayer>(); | |
| if (target == null || !target.IsAlive) | |
| return; | |
| if (target.Object != null && target.Object.Id == OwnerId) | |
| return; | |
| int dir = target.transform.position.x >= transform.position.x ? 1 : -1; | |
| target.RpcRequestPush(dir); | |
| target.TriggerHitEffect(); | |
| Runner.Despawn(Object); | |
| } | |
| } | |