コード例 #1
0
ファイル: Patrol.cs プロジェクト: lambertjamesd/douglas-game
    public override IState UpdateState(float deltaTime)
    {
        if (currentPatrol == null)
        {
            if (patrolParameters.leftProbability.GenerateValue())
            {
                direction = new Vector2(direction.y, -direction.x);
            }
            else if (patrolParameters.rightProbability.GenerateValue())
            {
                direction = new Vector2(-direction.y, direction.x);
            }
            else
            {
                direction = -direction;
            }

            currentPatrol = AsyncUtil.HandleNested(PatrolSegment(movement, direction, patrolParameters));
        }

        if (!currentPatrol.MoveNext())
        {
            currentPatrol = null;
        }

        if (vision != null)
        {
            Collider2D target = vision.GetVisibleObject();

            if (target != null)
            {
                return(onSight);
            }
        }

        return(null);
    }