예제 #1
0
    void FireLaser()
    {
        GameObject weapon;

        if (_isNegativeEffectActive == true || _isOmniShotActive == true)
        {
            _canFire = Time.time + _fireRate + _fireDelayIncrease;
        }
        else
        {
            _canFire = Time.time + _fireRate;
        }

        PlayClip(_laserClip);

        if (_isTripleShotActive == true)
        {
            int weaponType = _laserPrefab.GetWeaponType();
            for (int i = 0; i < _spawnPoints.Length; i++)
            {
                weapon = OnGetLaser?.Invoke(weaponType);
                if (weapon != null)
                {
                    weapon.transform.position = _spawnPoints[i].position;
                    weapon.SetActive(true);
                }
            }
        }
        else if (_isOmniShotActive == true)
        {
            int weaponType = _omniShotPrefab.GetWeaponType();
            weapon = OnGetWeapon?.Invoke(weaponType);
            if (weapon != null)
            {
                weapon.transform.position = transform.position;
                weapon.SetActive(true);
            }
        }
        else
        {
            int weaponType = _laserPrefab.GetWeaponType();
            weapon = OnGetLaser?.Invoke(weaponType);
            if (weapon != null)
            {
                weapon.transform.position = _spawnPoints[0].position;
                weapon.SetActive(true);
                _currentAmmo--;
                OnUpdateAmmo?.Invoke(_currentAmmo, _maxAmmo);
            }
        }
    }
예제 #2
0
    public GameObject GetInactiveWeapon(int weaponType)
    {
        GameObject weaponToSpawn = null;

        for (int i = 0; i < _weaponPool.Count; i++)
        {
            if (_weaponPool[i].activeInHierarchy == false)
            {
                WeaponID laser = _weaponPool[i].GetComponent <WeaponID>();
                if (weaponType == laser.GetWeaponType())
                {
                    weaponToSpawn = _weaponPool[i];
                    return(weaponToSpawn);
                }
            }
        }

        if (weaponToSpawn == null)
        {
            for (int i = 0; i < _weaponPrefabs.Length; i++)
            {
                WeaponID weapon = _weaponPrefabs[i].GetComponent <WeaponID>();
                if (weaponType == weapon.GetWeaponType())
                {
                    GameObject weaponPrefab = _weaponPrefabs[i];
                    GameObject weaponObj    = Instantiate(weaponPrefab, _weaponHolder);
                    _weaponPool.Add(weaponObj);
                    weaponToSpawn = weaponObj;
                    Debug.Log("Creating new Weapon.");
                    return(weaponToSpawn);
                }
            }
        }
        return(null);
    }
예제 #3
0
    public GameObject GetInactiveLaser(int laserType)
    {
        GameObject laserToSpawn = null;

        for (int i = 0; i < _laserPool.Count; i++)
        {
            if (_laserPool[i].activeInHierarchy == false)
            {
                WeaponID laser = _laserPool[i].GetComponent <WeaponID>();
                if (laserType == laser.GetWeaponType())
                {
                    laserToSpawn = _laserPool[i];
                    return(laserToSpawn);
                }
            }
        }

        if (laserToSpawn == null)
        {
            for (int i = 0; i < _laserPrefabs.Length; i++)
            {
                WeaponID laser = _laserPrefabs[i].GetComponent <WeaponID>();
                if (laserType == laser.GetWeaponType())
                {
                    GameObject laserPrefab = _laserPrefabs[i];
                    GameObject laserObj    = Instantiate(laserPrefab, _laserHolder);
                    _laserPool.Add(laserObj);
                    laserToSpawn = laserObj;
                    Debug.Log("Creating new Laser.");
                    return(laserToSpawn);
                }
            }
        }
        return(null);
    }
예제 #4
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab) && _isHomingMissileActive == true)
        {
            int        weaponType = _homingMissilePrefab.GetWeaponType();
            GameObject missile    = OnGetWeapon?.Invoke(weaponType);
            if (missile != null)
            {
                missile.transform.position = _spawnPoints[0].position;
                missile.SetActive(true);
                _currentMissiles--;
                if (_currentMissiles < 1)
                {
                    _currentMissiles       = 0;
                    _isHomingMissileActive = false;
                }
                OnUpdateMissiles?.Invoke(_currentMissiles, _numberOfMissiles);
            }
        }

        if (Input.GetKey(KeyCode.Space) && Time.time > _canFire && _currentAmmo > 0)
        {
            FireLaser();
        }

        CalculateMovement();
    }
예제 #5
0
    protected virtual void FireLaser()
    {
        float fireRate = Random.Range(_minFireDelay, _maxFireDelay);

        _canFire = Time.time + fireRate;

        PlayClip(_laserClip);

        GameObject enemyLaser;

        for (int i = 0; i < _laserSpawns.Length; i++)
        {
            int weaponType = _laserPrefab.GetWeaponType();
            enemyLaser = OnGetLaser?.Invoke(weaponType);
            if (enemyLaser != null)
            {
                enemyLaser.GetComponent <Laser>().AssignEnemyLaser();
                enemyLaser.transform.position = _laserSpawns[i].position;
                enemyLaser.SetActive(true);
            }
        }
    }
예제 #6
0
    void FireMissiles()
    {
        _canFire = _fireRate + Time.time;

        if (_missileSpawnPoints.Length >= 2)
        {
            GameObject missile;
            for (int i = 0; i < _missileSpawnPoints.Length; i++)
            {
                int weaponType = _missilePrefab.GetWeaponType();
                missile = OnGetWeapon?.Invoke(weaponType);
                if (missile != null)
                {
                    missile.transform.position = _missileSpawnPoints[i].position;
                    missile.SetActive(true);
                    if (_player != null)
                    {
                        missile.GetComponent <HomingMissile>().AssignEnemyMissile(_player.transform);
                    }
                }
            }
        }
        else if (_missileSpawnPoints.Length > 0)
        {
            GameObject missile;
            int        weaponType = _missilePrefab.GetWeaponType();
            missile = OnGetWeapon?.Invoke(weaponType);
            if (missile != null)
            {
                missile.transform.position = _missileSpawnPoints[0].position;
                missile.SetActive(true);
                if (_player != null)
                {
                    missile.GetComponent <HomingMissile>().AssignEnemyMissile(_player.transform);
                }
            }
        }
    }
예제 #7
0
    protected override void FireLaser()
    {
        float fireRate = Random.Range(_minFireDelay, _maxFireDelay);

        _canFire = Time.time + fireRate;

        int        weaponType = _minePrefab.GetWeaponType();
        GameObject mine       = GetWeapon(weaponType);

        if (mine != null)
        {
            mine.transform.position = _laserSpawns[0].position;
            mine.SetActive(true);
        }
    }