void Update()
 {
     if (tag == "ProjectileHero" && !bndCheck.onCamera(transform.position))
     {
         Destroy(gameObject);
     }
     if (rigid.velocity.magnitude < 30)
     {
         Destroy(gameObject);
     }
 }
Beispiel #2
0
    public void SpawnEnemy()
    {
        int        ndx = Random.Range(0, prefabEnemies.Length);
        GameObject go  = Instantiate <GameObject>(prefabEnemies[ndx]);

        float enemyPadding = enemyDefaultPadding;

        if (go.GetComponent <BoundsCheck>() != null)
        {
            enemyPadding = Mathf.Abs(go.GetComponent <BoundsCheck>().radius);
        }

        Vector3 pos  = Vector3.zero;
        float   xMin = -bndCheck.playArea.x + enemyPadding;
        float   xMax = bndCheck.playArea.x - enemyPadding;
        float   yMin = -bndCheck.playArea.y + enemyPadding;
        float   yMax = bndCheck.playArea.y - enemyPadding;

        pos.x = Random.Range(xMin, xMax);
        pos.y = Random.Range(yMin, yMax);

        //Ensures spawning off camera
        while (bndCheck.onCamera(pos))
        {
            pos.x = Random.Range(xMin, xMax);
            pos.y = Random.Range(yMin, yMax);
        }

        go.transform.position = pos;

        enemyCount++;

        if (enemyCount < maxEnemies)
        {
            Invoke("SpawnEnemy", 1f / enemySpawnPerSecond);
        }
    }