コード例 #1
0
ファイル: BossScript.cs プロジェクト: trimute2/Asteriods
 public void Move()
 {
     //dont move if recharging
     if (volleyTime == 0)
     {
         //determine if bullets are in avoid distance
         List <GameObject> bullets  = bulletManager.BulletsList;
         float             distance = float.MaxValue;
         GameObject        closest  = null;
         //get closest bullet
         for (int i = bullets.Count - 1; i >= 0; i--)
         {
             float dist = (this.transform.position - bullets [i].transform.position).sqrMagnitude;
             if (dist < distance)
             {
                 distance = dist;
                 closest  = bullets [i];
             }
         }
         float disti = (this.transform.position - target.transform.position).sqrMagnitude;
         //check if the player is closer than any of the bullets
         if (disti < distance)
         {
             distance = disti;
             closest  = target;
         }
         //if either the player or any of the players bullets are with in a certain radius avoid the object
         if (distance < avoidRadius * avoidRadius)
         {
             FacePoint(closest.transform.position, -1);
             MovePoint(closest.transform.position, -1);
             shotVolley = shotsPerVolley;
         }
         else
         {
             //move away from the edge
             if (!EdgeMove())
             {
                 //if not close to the edge face the player
                 FacePoint(target.transform.position);
                 //if shots are left in a volley fire at the player
                 if (volleyTime == 0 && bulletManager.AddBossBullet(engine.Position, engine.Heading))
                 {
                     //if a shot is fired detract shot volley
                     shotVolley--;
                     if (shotVolley <= 0)
                     {
                         //if there are no volleys left set volley time to the volley rate
                         //add the delta time to the volley rate because the tick is called after this (not sure why im only doing this here)
                         volleyTime = volleyRate + Time.deltaTime;
                     }
                 }
             }
         }
     }
     //tick the volley time and call the engines move
     TickVolleyTime();
     engine.Move();
 }