47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using System.Collections;
|
|
using Fusion;
|
|
using UnityEngine;
|
|
|
|
public class AlarmTrap : TrapBase
|
|
{
|
|
[Header("Alarm Visual Prefab")]
|
|
[SerializeField] private GameObject pingIndicatorPrefab; // Prefab representing the warning icon visible through walls
|
|
|
|
protected override void OnTriggered(GameObject victim)
|
|
{
|
|
// Server: Notify the Trapper who placed this trap
|
|
if (Owner != PlayerRef.None)
|
|
{
|
|
RPC_NotifyAlarmPing(Owner, victim.transform.position, trapData.EffectDuration);
|
|
}
|
|
|
|
// Play alarm loop sound or VFX for a duration, then despawn
|
|
StartCoroutine(AlarmDurationRoutine());
|
|
}
|
|
|
|
[Rpc(RpcSources.StateAuthority, RpcTargets.InputAuthority)]
|
|
private void RPC_NotifyAlarmPing([RpcTarget] PlayerRef targetPlayer, Vector3 position, float duration)
|
|
{
|
|
Debug.Log($"[Client] Trapper notified! Seeker tripped alarm at position: {position}");
|
|
|
|
// Instantiate the warning indicator at the Seeker's position
|
|
if (pingIndicatorPrefab != null)
|
|
{
|
|
GameObject indicator = Instantiate(pingIndicatorPrefab, position + Vector3.up * 1.5f, Quaternion.identity);
|
|
Destroy(indicator, duration);
|
|
}
|
|
else
|
|
{
|
|
// Fallback: log warning or use debug line draw
|
|
Debug.DrawLine(position, position + Vector3.up * 5f, Color.red, duration);
|
|
}
|
|
}
|
|
|
|
private IEnumerator AlarmDurationRoutine()
|
|
{
|
|
// Stay active to play audio alarm for a bit
|
|
yield return new WaitForSeconds(trapData.EffectDuration);
|
|
DespawnTrap();
|
|
}
|
|
}
|