Using IEnumerator in an Ability class

Silver100

Member
Is it possible to use IEnmuerator delay inside an ability script/class? Basically just trying to add a small delay to allow for other events to happen before ability starts.

So far I have struggled highlights red but would usually be able to get this to work in monobehavior.
Code:
using Opsive.UltimateCharacterController.Character.Abilities;
using System.Collections;// I believe should usually enable co - routines

 public override void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Jetpack")
        {
            StartCoroutine(delay(v: 30)); // highlights red?
        }
        IEnumerator delay(int v)
        {
            yield return new WaitForSeconds(1.0f);//
            Jetpackpactive = true;
        }
 
Last edited:
No, that method isn't overridden for the Ability class. Instead you should use the scheduler.
 
Thanks I see I should be using this name space Game; For some reason the word Scheduler does not pick up in my script
I did try and figure registering an event but struggled with that so far is that is the issue.

Code:
using UnityEngine;//
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Game;

if (other.tag == "Jetpack")
        {
            var scheduledEvent = Scheduler.Schedule(1.5f, Jetpackactive, true);
            Scheduler.Cancel(scheduledEvent);// in red unrecognised
        }
 
Last edited:
Thanks, would the 'Jetpackactive' (now flagging red) need to be a registered event? The example below 'Explode' is used, would this be set as registered event. Basically is there something else I need to do? I read through the events documents too but for some reason struggled to grasp it at the moment, do I need to fully understand the events process before moving on to setting up a scheduled event?

Code:
// The scheduler class is in the Game namespace.
using Opsive.UltimateCharacterController.Game;

// Schedule the Explode method to occur in 1.5 seconds. The first parameter of Explode will have a value of true.
var scheduledEvent = Scheduler.Schedule(1.5f, Explode, true)// here I have applied Jetpackactive in my scenario

// Check the active state of the scheduled event.
Debug.Log("Is active: " + scheduledEvent.Active);

// Cancel the scheduled event
Scheduler.Cancel(scheduledEvent);
 
Last edited:
No, you don't need to register anything with the scheduler. You are cancelling the event though immediately after so that will prevent it from firing. If you do a search within the UCC codebase you'll find a lot of examples.
 
Thanks. I spent some time looking at the examples like the methods used in DamageVisualization & Block trying to incorporate but I struggled. I did try instead changing size order of the pick up colliders (x2 visual and an ability tags ) so the characters backpack and jetpack, swap over in advance before the flight ability starts. A Larger tagged collider causes the visual swap smaller tagged collider starts ability. I did try with a co-routine to delay start time of ability through a mono trigger collider tag which works, also variances in size differences too. When passing through at high speeds/forces though results are not 100% its possible to start jetpack flight with no switch of a visual jet pack. Also tried to enable objects in ability class trough tag. It would be better to figure out the scheduler somehow though to resolve.Pic4.png
 
Last edited:
Top