Пример #1
0
    void Start()
    {
        transform.localPosition = transform.parent.InverseTransformPoint(transform.position);
        bulletController        = this.GetComponent <BulletController>();
        bulletController.ATK    = UnityEngine.Random.Range(towerController.attribute.MinATK
                                                           + towerController.Bonus.ATK, towerController.attribute.MaxATK + towerController.Bonus.ATK);
        this.enemy = towerAction.enemy;

        switch (towerController.chaseType)
        {
        case EBulletChaseType.CHASE:
            bulletTemplate = new BulletChase();
            break;

        case EBulletChaseType.DROP:
            bulletTemplate = new BulletDrop();
            break;

        case EBulletChaseType.EXPLOSION:
            bulletTemplate = new BulletExplosion();
            break;

        case EBulletChaseType.BOMB:
            bulletTemplate = new BulletBomb();
            break;

        case EBulletChaseType.ARCHITECT:
            bulletTemplate = new BulletArchitect();
            break;
        }

        bulletTemplate.updateEnemy(enemy);
        bulletTemplate.Initalize(bulletController);
        bulletTemplate.Update();
    }
Пример #2
0
    void Start()
    {
        transform.localPosition = transform.parent.InverseTransformPoint(transform.position);
        bulletController = this.GetComponent<BulletController>();
        bulletController.ATK = UnityEngine.Random.Range(towerController.attribute.MinATK 
		     + towerController.Bonus.ATK, towerController.attribute.MaxATK + towerController.Bonus.ATK);
        this.enemy = towerAction.enemy;
  
        switch (towerController.chaseType)
        {
            case EBulletChaseType.CHASE:
                bulletTemplate = new BulletChase();
                break;
            case EBulletChaseType.DROP:
                bulletTemplate = new BulletDrop();
                break;
            case EBulletChaseType.EXPLOSION:
                bulletTemplate = new BulletExplosion();
                break;
            case EBulletChaseType.BOMB:
                bulletTemplate = new BulletBomb();
                break;
            case EBulletChaseType.ARCHITECT:
                bulletTemplate = new BulletArchitect();
                break;
        }

        bulletTemplate.updateEnemy(enemy);
        bulletTemplate.Initalize(bulletController);
        bulletTemplate.Update();
    }
 /// <summary>
 /// Method used to spawn a bullet from the object pool.
 /// When called it will move the new bullet from one list to another, return the bullet's references in order to be used by the Pistol Controller.
 /// After being called the bullet is only referenced, no operations are done the actual bullet, those are done in the pistol/bullet controller.
 /// </summary>
 /// <param name="isBulletAvailable">Out variable that says if there was an available bullet to be used.</param>
 /// <returns></returns>
 public BulletTemplate SpawnBullet(out bool isBulletAvailable) {
     BulletTemplate temp = default;
     if(_availaleBullets.Count > 0) {
         temp = _availaleBullets[0];
         _onUseBullets.Add(temp);
         _availaleBullets.Remove(temp);
         isBulletAvailable = true;
     } else {
         isBulletAvailable = false;
     }
     
     return temp;
 }
    /// <summary>
    /// On Awake the bullet spawn manager instantiates the maximum number of bullets needed to be used.
    /// Instantiate the bullet prefab (Parent + 2 Childs [Bullet, HitFX]).
    /// Create a temporal BulletTemplate that contains the info of the newly created bullet (Reference to the BulletController that has the references to the bullet's components and methods).
    /// Pass the BulletTemplate to the BulletController in order for each bullet to know which one they are so that I can reference them back when disabling.
    /// Add this new bullet object to the available list.
    /// So far the counter is only to diferenciate between each instance of bullets.
    /// </summary>
    private void Awake() {
        _availaleBullets = new List<BulletTemplate>();
        _onUseBullets = new List<BulletTemplate>();

        for (int i = 0; i < _maxNumberOfBullets; i++) {
            BulletTemplate temp = default;
            temp.bulletController = GameObject.Instantiate(_templateBullet.bulletController.gameObject, _bulletParent).GetComponent<BulletController>();
            temp.index = _counter;
            temp.bulletController.SetBulletTemplate(temp);
            _availaleBullets.Add(temp);
            ++_counter;
        }
        _onUseBullets.Clear();
    }
 /// <summary>
 /// Reenable bullet to be used.
 /// </summary>
 /// <param name="temp">Bullet's template reference. Used to delete the correspondent item from the available/onUse lists.</param>
 public void DespawnBullet(BulletTemplate temp) {
     temp.bulletController.gameObject.SetActive(false);
     _onUseBullets.Remove(temp);
     _availaleBullets.Add(temp);
 }