I’m trying to set up an effect strategy that will enable/disable a particle effect attached to the target. The idea is that if I cast a fire spell, the targets will activate an “onfire” particle effect and take damage over time, and after the DoT expires deactivate the effect. For the most part this all works, with one issue:
I can not get the “disableFX” portion of the script to work, it doesn’t seem to ever get called.
Here is my effect strategy:
using System;
using System.Collections;
using System.Collections.Generic;
using Tribes.Combat;
using UnityEngine;
namespace Tribes.Abilities.Effects
{
[CreateAssetMenu(fileName = "Spawn Status FX", menuName = "Abilities/Effects/Spawn Status FX", order = 0)]
public class SpawnStatusFX : EffectStrategy
{
[SerializeField] float destroyDelay = -1;
public override void StartEffect(AbilityData data, Action finished)
{
data.StartCoroutine(Effect(data, finished));
}
private IEnumerator Effect(AbilityData data, Action finished)
{
IEnumerable<GameObject> targets = data.GetTargets();
Debug.Log(targets);
foreach (var target in targets)
{
target.GetComponentInChildren<StatusVFX>().EnableFireVFX();
}
if (destroyDelay > 0)
{
yield return new WaitForSeconds(destroyDelay);
Debug.Log("Waited for: " + destroyDelay);
foreach (var target in targets)
{
target.GetComponentInChildren<StatusVFX>().DisableFireVFX();
Debug.Log("called disable fire ");
}
}
finished();
}
}
}
and here is the component it calls, which is attached to an object childed under both the player and npc gameobjects.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Tribes.Combat
{
public class StatusVFX : MonoBehaviour
{
public void EnableFireVFX()
{
transform.GetChild(0).gameObject.SetActive(true);
Debug.Log(gameObject.transform.parent + " set on fire ");
}
public void DisableFireVFX()
{
transform.GetChild(0).gameObject.SetActive(false);
Debug.Log(gameObject.transform.parent + " extinguished ");
}
}
}
Based on the debug logs, it looks like its working up until the foreach loop after the WaitForSeconds line.