Exemplo n.º 1
0
        void Update()
        {
            try
            {
                Direction availableDirections = pathFinding.FirstPassRaycast();
                if (availableDirections == Direction.None)
                {
                    Debug.Log("STUCK! Cheating!");
                    transform.Rotate(0, 180, 0);
                }
                else
                {
                    // Do collision detection; if nothing is blocking, let the behavior decide the movement
                    Vector3 turningDirection = pathFinding.DetermineTurningDirection(availableDirections);
                    if (turningDirection != Vector3.zero)
                    {
                        transform.Rotate(turningDirection * ship.AngularVelocity * Time.deltaTime);
                    }
                    else
                    {
                        behavior.Turn();
                    }
                    Move();
                }
                behavior.Attack();
            }
            catch (BehaviorNotApplicableException e)
            {
                if (e.Reason == BehaviorChangeReason.TargetAcquired)
                {
                    Attack(e.Target);
                }
                else
                {
                    behavior = DetermineDefaultBehavior();
                    behavior.Commence();

                    // Forget whoever fired at this ship
                    enemyToRetaliateAgainst = null;
                }
            }
            Debug.Log(behavior.Describe());
        }