SWS-Smarta / project /Assets /Scripts /Game /Obstacle.cs
alfapro's picture
Clean deploy: Code only for SWS
defab59
Raw History Blame Contribute Delete
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;
}
}