コード例 #1
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     if (coll.gameObject.tag.Equals("Creep"))
     {
         if (enemies.Count == 0)
         {
             enemies.Add(coll.gameObject);
             //to take into account of an empty list
             return;
         }
         if (enemies.Contains(coll.gameObject))
         {
             return;
             //stops if the list already has the enemy
         }
         for (int i = 0; i < enemies.Count; i++)
         {
             Creep enemy = enemies[i].GetComponent <Creep> ();
             if (enemy.GetProgress() < coll.gameObject.GetComponent <Creep>().GetProgress())
             {
                 enemies.Insert(i, coll.gameObject);
                 //insterts the target on the list in terms of how long has it existed on the map
                 return;
             }
         }
         enemies.Add(coll.gameObject);
     }
 }