Spaces:
Sleeping
Sleeping
File size: 984 Bytes
defab59 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 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;
}
}
|