public void Shoot(float minfreq, float maxfreq) { //chance to switch shotbehavior Shot temp = new Shot(); temp.Chance(); switch (_shootBehavior) { case ShootBehavior.RANDOM: _nextFire = _weapon.Shoot(transform.position, transform.position.y > _player.transform.position.y ? Quaternion.Euler(0, 0, transform.eulerAngles.z - 180f) : Quaternion.identity, temp); _nextFire += Random.Range(minfreq, maxfreq); break; case ShootBehavior.TIMESCONSECUTIVE: if (consecutiveShotsLeft > 0) { _nextFire = _weapon.Shoot(transform.position, transform.position.y > _player.transform.position.y ? Quaternion.Euler(0, 0, transform.eulerAngles.z - 180f) : Quaternion.identity, temp); consecutiveShotsLeft -= 1; } else { //switch to other type idk ChangeShootingBehavior(1); } break; } }
// //private SpawnManager _spawnManager; //[SerializeField] //private int _score = 0; // //[SerializeField] //private UIManager _uiManager; // //[SerializeField] //private AudioClip _laserSound; //private AudioSource _audioSource; // void Start() { homing = GetComponent <HomingOverlapTarget>(); collider = GetComponent <BoxCollider2D>(); sprite = GetComponent <SpriteRenderer>(); homing.ResizeTargetAmount(homingActive); //current position at start. transform.position = new Vector3(0, 0, 0); //get stats from first weapon InitializeWeapon(0); _currentSpeed = _baseSpeed; _thrusterVisual.gameObject.SetActive(false); _currentAmmo = _maxAmmo; //populate queue //for queue size. enqueue the initialized shot. furhter ones will be recycled. for (int i = 0; i < _shotQueueSize; i++) { Shot temp = new Shot(); temp.Chance(); _shotQueue.Enqueue(temp); OnShotEnqueue(temp.critical); } Debug.Log(_shotQueue.Count); OnFireAmmoUpdate(_currentAmmo, _maxAmmo); //fill health _currentLife = 1; for (int i = 1; i < _baseLife; i++) { _currentLife += 1; OnHealthUpdate(_currentLife); } //show shield. 111 = white = original sprite color _shieldVisual.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 1); // // _spawnManager = GameObject.Find("SpawnManager").GetComponent<SpawnManager>(); // if(_spawnManager== null){ // Debug.LogError("The spawnmanager is NULL"); // } // _uiManager = GameObject.Find("Canvas").GetComponent<UIManager>(); // if(_uiManager== null){ // Debug.LogError("The _uiManager is NULL"); // } // _shieldVisual.SetActive(false); // // _audioSource = GetComponent<AudioSource>(); // if(_audioSource == null){ // Debug.LogError("The audiosource is NULL"); // }else{ // _audioSource.clip = _laserSound; // } }
public void AddAmmo(int ammount) { for (int i = _currentAmmo; i < _shotQueueSize; i++) { Shot temp = new Shot(); temp.Chance(); _shotQueue.Enqueue(temp); OnShotEnqueue(temp.critical); } _currentAmmo = Mathf.Clamp(_currentAmmo + ammount, 0, _maxAmmo); OnFireAmmoUpdate(_currentAmmo, -1); }
void ShootLaser() { Shot temp = _shotQueue.Dequeue(); OnShotDequeue(temp.critical); //basic shot _nextFire = _currentWeapon.Shoot(_shotSpawns.GetChild(0).position, Quaternion.identity, temp); if (mirrorActive) { Debug.Log("mirrorshot"); _currentWeapon.Shoot(_shotSpawns.GetChild(0).position, Quaternion.Euler(0, 0, -180), temp); } //there should be a way to exclude the left and right ones from mirror...they are repeated twice on each side lol for (int i = 1; i < _shotSpawns.childCount; i++) { if (_shotSpawns.GetChild(i).gameObject.activeSelf) { _currentWeapon.Shoot(_shotSpawns.GetChild(i).position, _shotSpawns.GetChild(i).rotation, temp); if (mirrorActive) { _currentWeapon.Shoot(_shotSpawns.GetChild(i).position, Quaternion.Euler(0, 0, _shotSpawns.GetChild(i).eulerAngles.z - 180f), temp); } } } _currentAmmo -= 1; OnFireAmmoUpdate(_currentAmmo, -1); if (_currentAmmo >= _shotQueueSize) { temp.Chance(); _shotQueue.Enqueue(temp); OnShotEnqueue(temp.critical); } Debug.Log(_shotQueue.Count); //the next time it will allow to fire in the future. //_nextFire = Time.time + _fireRate; // // if(tripleShotActive){ // Instantiate(_triplePrefab, transform.position, Quaternion.identity); // }else{ //Instantiate(_laserPrefab, _shootingPoint.position, Quaternion.identity); // } // //sound effect // _audioSource.Play(); }