Hey guys I’m having a little issue with using an IENumerator,
I’m currently trying to add an object to a list, apply an effect to the object
to the list for a certain duration then remove them from the list, the purpose of
the list to is disallow the object from having the effect applied to it while
the effect is already applied.
//abilityEffects contains a list of AbilityEffect objects
Public class ApplyAbilityEffects : MonoBehaviour
{
foreach (AbilityEffect abilityEffect in abilityEffects)
{
StartCoroutine (abilityEffect.performBehaviour (other.gameObject));
}
}
//EffectMovementModifier is a type of AbilityEffect
public class EffectMovementModifier : AbilityEffect
{
public override IEnumerator performBehaviour(GameObject inOther)
{
UnityEngine.Debug.Log ("test1");
//MovementModification
if (!objectsEffected.Contains(inOther.name))
{
inOther.GetComponent<BeastlingParent> ().getContainer ().getModifiers ().setMovementModifier (movementModifierAmount);
objectsEffected.Add(inOther.name);
UnityEngine.Debug.Log ("test2");
yield return new WaitForSeconds (2);
}
else
{
//MovementDemodification
inOther.GetComponent<BeastlingParent> ().getContainer ().getModifiers ().setMovementModifier (-movementModifierAmount);
objectsEffected.Remove(inOther.name);
UnityEngine.Debug.Log ("test3");
}
yield return null;
}
}
My issue is that ‘movement’ flickers on and off rather than waiting for 2 seconds.
when running, the debug.log tests all run simultaniously, rather than test 3 running once every 2 seconds.
Any insight into this would be greatly appreciated,
Bazzalisk.
You say test 3 should run every 2 seconds, but there is only a yield Waitforseconds() in test 2. It would seem your flickering is the rapid removal of any effects in the object continually in test 3. I don't entirely understand what you are checking with the other.name
– Hazzanger