Exemple #1
0
    public IEnumerator DoLogic()
    {
        while (!damageable.IsDead)
        {
            yield return(Patrol.PatrolUntilSight(movement, patrolParameters, sight));

            movement.LockRotation();

            Collider2D target = sight.GetVisibleObject();

            if (target != null)
            {
                yield return(LineUpShot.LineUp(target.transform, shootFrom.transform, movement, sight, targetOffset, lineUpSpeed));

                if (sight.canSeeObject(target.gameObject))
                {
                    shootFrom.Fire(gunStats);
                    gunStats.SetShotsLeft(variableStore, gunStats.GetShotsLeft(variableStore) - 1);
                    yield return(AsyncUtil.Pause(postFireDelay));

                    if (gunStats.GetShotsLeft(variableStore) <= 0)
                    {
                        var possibleCover = pathfinder.GetPathFinding().FindCover(target.transform.position, 0.5f);

                        pathfinder.PathToNearest(possibleCover);

                        movement.UnlockRotation();

                        var previousLocation = transform.position;

                        yield return(pathfinder.FollowPath());

                        movement.TargetVelocity = Vector2.zero;

                        yield return(ReloadGun.ReloadAnimation(gunStats, reloadLocation, variableStore));

                        pathfinder.PathTo(previousLocation);

                        yield return(pathfinder.FollowPath());

                        movement.LockRotation();
                    }
                }
            }

            movement.UnlockRotation();
        }
    }
    public IEnumerator DoLogic()
    {
        while (!damageable.IsDead)
        {
            yield return(Patrol.PatrolUntilSight(movement, patrolParameters, sight));

            movement.LockRotation();

            Collider2D target = sight.GetVisibleObject();

            if (target != null)
            {
                yield return(LineUpShot.LineUp(target.transform, shootFrom.transform, movement, sight, targetOffset, lineUpSpeed));

                if (sight.canSeeObject(target.gameObject))
                {
                    if (animation != null)
                    {
                        animation.SetTigger("Firing");
                    }
                    yield return(AsyncUtil.Pause(preFireDelay));

                    shootFrom.Fire(gunStats);
                    gunStats.SetShotsLeft(variableStore, gunStats.GetShotsLeft(variableStore) - 1);
                    yield return(AsyncUtil.Pause(postFireDelay));

                    if (gunStats.GetShotsLeft(variableStore) <= 0)
                    {
                        yield return(ReloadGun.ReloadAnimation(gunStats, reloadLocation, variableStore));
                    }
                }
            }

            movement.UnlockRotation();
        }
    }