90 lines
1.7 KiB
C#
90 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class NetworkedAntiProjectile : MonoBehaviour
|
|
{
|
|
[Header("Visuals")]
|
|
[SerializeField] private GameObject visuals;
|
|
|
|
[Header("Hit Filtering Tag")]
|
|
[SerializeField] private Taggable antiProjectileTag;
|
|
|
|
[Header("Set by code")]
|
|
public Taggable ownerTag;
|
|
public AntiProjectileAbility ability;
|
|
public float duration;
|
|
public bool followUser;
|
|
public bool breakOnHit;
|
|
|
|
|
|
private bool waitingForDestroy = false;
|
|
|
|
private float endTime;
|
|
|
|
public UnityEvent onProjectileBlocked = new UnityEvent();
|
|
|
|
private void Awake()
|
|
{
|
|
antiProjectileTag = GetComponent<Taggable>();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
waitingForDestroy = false;
|
|
|
|
|
|
StartCoroutine(SelfDestruct());
|
|
|
|
if (followUser)
|
|
StartCoroutine(FollowUser());
|
|
|
|
}
|
|
|
|
IEnumerator FollowUser()
|
|
{
|
|
endTime = Time.time + duration;
|
|
while (Time.time < endTime)
|
|
{
|
|
this.transform.position = ownerTag.transform.position;
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
visuals.SetActive(false);
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SendBlockNotice()
|
|
{
|
|
if (waitingForDestroy) return;
|
|
|
|
waitingForDestroy = true;
|
|
|
|
visuals.SetActive(false);
|
|
|
|
StartCoroutine(DelayedDestroy());
|
|
}
|
|
|
|
|
|
IEnumerator DelayedDestroy()
|
|
{
|
|
visuals.SetActive(false);
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
Destroy(this.gameObject);
|
|
}
|
|
|
|
IEnumerator SelfDestruct()
|
|
{
|
|
yield return new WaitForSeconds(duration);
|
|
|
|
waitingForDestroy = true;
|
|
|
|
StartCoroutine(DelayedDestroy());
|
|
}
|
|
}
|