//fires next projectile in line. if no special projectile loaded, fires a default bouncing projectile private void FireCannon() { if (shotCooldown > 0f) { return; } GameObject nuProjectile = Instantiate <GameObject>(projectilePrefab); nuProjectile.transform.position = cannonBarrel.transform.position + muzzlePoint; ProjectileScript projScrip = nuProjectile.GetComponent <ProjectileScript>(); //here we check the special bullets loaded ProjectileScript.ProjectileType nextType = loadedProjectile ? loadedType : ProjectileScript.ProjectileType.Bouncer; if (loadedProjectile) { loadedProjectile = false; } projScrip.Shoot(cannonBarrel.transform.position + muzzlePoint, GameSettings.instance.projectileStartSpeed * cannonBarrel.forward, nextType); //we set the cooldown cooldownGraphic.fillAmount = 1f; cooldownGraphic.transform.GetChild(0).gameObject.SetActive(true); shotCooldown = GameSettings.instance.shootCooldown; }
public void Shoot(ShootParameters shootParameters, DamageTag damageTag) { int projectileIndex = shootParameters.GetProjectilePrefab.GetPoolingIndex; ProjectileScript projPrefab = shootParameters.GetProjectilePrefab; float imprecisionAngle = shootParameters.GetImprecisionAngle; for (int i = 0; i < shootParameters.GetNumberOfProjectilesPerShot; i++) { ProjectileScript newProj = poolingManager.GetProjectileFromPool(projectileIndex); if (newProj == null) { break; } newProj.transform.position = transform.position; newProj.transform.rotation = Quaternion.identity; //ProjectileScript newProj = Instantiate(projPrefab, transform.position, Quaternion.identity); Vector3 shootDirection = Quaternion.Euler(0, 0, Random.Range(-imprecisionAngle / 2, imprecisionAngle / 2)) * GetTrueDirection; newProj.Shoot(shootParameters.GetProjectileParameters, shootDirection, damageTag); } }