alfapro's picture
Clean deploy: Code only for SWS
defab59
Raw History Blame Contribute Delete
1.33 kB
using Fusion;
using UnityEngine;
public class ItemBox : NetworkBehaviour
{
public ItemType[] items = new ItemType[] {
ItemType.Shield, ItemType.Speed, ItemType.Trap, ItemType.Projectile
};
public GameObject breakEffectPrefab;
public float breakEffectLife = 1.2f;
public override void Spawned()
{
if (items == null || items.Length == 0)
items = new ItemType[] { ItemType.Shield, ItemType.Speed };
}
void OnTriggerEnter(Collider other)
{
if (!Object.HasStateAuthority)
return;
DinoPlayer player = other.GetComponentInParent<DinoPlayer>();
if (player == null || !player.IsAlive)
return;
if (player.HeldItem != 0)
return;
ItemType picked = items[Random.Range(0, items.Length)];
player.GiveItem(picked);
RpcBreakEffect(transform.position);
Runner.Despawn(Object);
}
[Rpc(RpcSources.StateAuthority, RpcTargets.All)]
void RpcBreakEffect(Vector3 pos)
{
if (breakEffectPrefab == null)
return;
GameObject fx = Instantiate(breakEffectPrefab, pos, Quaternion.identity);
Destroy(fx, breakEffectLife);
DinoAudio audio = DinoAudio.Instance;
if (audio != null)
audio.PlayBoxBreak();
}
}