示例#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());
        }
示例#2
0
 public void Attack(GameObject target)
 {
     behavior = new AttackingBehavior(gameObject, rightGunTransform, leftGunTransform, target);
     behavior.Commence();
 }
示例#3
0
 void Start()
 {
     pathFinding = new PathFinding(transform);
     behavior    = DetermineDefaultBehavior();
     behavior.Commence();
 }