Example #1
0
    // Shooting
    void TargetEnemy()
    {
        if (targetShip != null && Vector2.Distance(transform.position, targetShip.transform.position) < attackRange && targetShip.gameObject.activeSelf)
        {
            return;
        }

        float minDis = 10f;

        targetShip = null;
        AlienSpaceship closestShip = null;

        foreach (AlienSpaceship ap in SpaceShipSpawner.allShips)
        {
            if (!ap.gameObject.activeSelf)
            {
                continue;
            }

            float apDis = Vector2.Distance(transform.position, ap.transform.position);

            if (apDis < minDis && apDis < attackRange)
            {
                minDis      = apDis;
                closestShip = ap;
            }
        }

        targetShip = closestShip;
    }
Example #2
0
    IEnumerator SpawnerUpdate()
    {
        while (spawning)
        {
            if (inactivePool.Count > 0)
            {
                AlienSpaceship newShip = inactivePool.Dequeue();
                newShip.gameObject.SetActive(true);
            }

            yield return(new WaitForSeconds(Mathf.Max(6f - (GameController.instance.level / 3f) - ((Time.time - sceneStartTime) / 40f), 0.1f)));
        }
    }
Example #3
0
 void Despawn(AlienSpaceship alienShip)
 {
     Instantiate(scrap, alienShip.transform.position, Quaternion.identity);
     alienShip.gameObject.SetActive(false);
     inactivePool.Enqueue(alienShip);
 }
Example #4
0
 public void AlienInvadedEvent(AlienSpaceship alienShip)
 {
     Health -= 1;
 }