#Async stuff

1 messages · Page 1 of 1 (latest)

zinc palm
#

So I did this:

        private Subject<bool> m_ShootAnimation = new();
        private IObservable<bool> ShootAnimation() => m_ShootAnimation;

        public void Shoot() //Called in animation events
        {
            m_ShootAnimation.OnNext(true);
        }
        
        protected override async UniTask ExecuteBehavior()
        {
            while (isActiveAndEnabled && Enemy.Targets[0] != null)
            {
                await GotoOverSeconds((Vector2)transform.position + FindStrafeDirection(strafeDistance, strafeRadius) * strafeDistance, 1 /         (Enemy.Stats.GetStat(Stat.MoveSpeed) * strafeSpeed));
                PlayAnimation(EnemyAnimationState.Stop);
                await ShootAnimation().First(); //New thing to fix it
                ShootProjectile(shootProjectile, transform.position, GetDirectionToFirstTarget());
                await UniTask.Delay(TimeSpan.FromSeconds(2));
            }
        }
#

and it worked perfect first try!

#

But maybe there is an even simpler way to do it since I don't need to pass any values, I just need to notify it

#

Also: Is it fine to have behaviors with repeated logic have a generic, not enemy-specific name and re-use them? It will work properly that way but idk if it's bad practice or whatever.

zinc palm
#

cool thanks

lament timber
#

you can use a unitaskcompletionsource instead of an iobservable for stuff like a complex animation that a bunch of things do. that way if it had already run for some reason, it will just work - meaning it will not wait for ANOTHER shoot animation

lament timber
zinc palm
#

I need a way to like reset it, would I need to re-instantiate it?

#

Seems like re-instantiating it is working

lament timber
#

okay i would do it the original way

#

sorry about that but it works