示例#1
0
 //
 void IntroduceBullets(BulletTypePool bulletTypePool, GameObject bulletPrefab, int bulletsToIntroduce)
 {
     for (int i = 0; i < bulletsToIntroduce; i++)
     {
         GameObject newBullet = Instantiate(bulletPrefab, Vector3.zero, Quaternion.identity);
         newBullet.SetActive(false);
         bulletTypePool.reserveBullets.Add(newBullet);
     }
 }
示例#2
0
    //
    public void RegisterBullets(GameObject bulletPrefab, float fireRate, float bulletLifeTime)
    {
        //
        int    maxExistantBullets = (int)(bulletLifeTime * fireRate);
        string enteringBulletName = bulletPrefab.name;
        Bullet bulletScript       = bulletPrefab.GetComponent <Bullet>();

        // Si todavía no hay ninguna creada vamos directamente con esto

        /*if (bulletPoolsPerType.Count == 0)
         * {
         *  BulletTypePool newBulletTypePool = new BulletTypePool(enteringBulletName);
         *  bulletPoolsPerType.Add(newBulletTypePool);
         *  //
         *  newBulletTypePool.bulletScript = bulletScript;
         *  newBulletTypePool.dangerousEnough = bulletScript.dangerousEnough;
         *  // Y ahora metemos las balas
         *  IntroduceBullets(newBulletTypePool, bulletPrefab, maxExistantBullets);
         *  return;
         * }*/
        // Cuando ya hay por lo menos una creada
        for (int i = 0; i < bulletPoolsPerType.Count; i++)
        {
            //string enteringBulletName = bulletPrefab.name;
            if (bulletPoolsPerType[i].prefabName.Equals(enteringBulletName))
            {
                //
                IntroduceBullets(bulletPoolsPerType[i], bulletPrefab, maxExistantBullets);
                return;
            }
        }

        // Y en caso de que entre una no registrada
        BulletTypePool newBulletTypePool = new BulletTypePool(enteringBulletName);

        bulletPoolsPerType.Add(newBulletTypePool);
        //
        newBulletTypePool.bulletScript    = bulletScript;
        newBulletTypePool.dangerousEnough = bulletScript.dangerousEnough;
        // Y ahora metemos las balas
        IntroduceBullets(newBulletTypePool, bulletPrefab, maxExistantBullets);
        return;
    }