protected void InitializeBullet(GameObject bullet) { DamageSystem bulletDamage = bullet.GetComponent <DamageSystem>(); if (bulletDamage == null) { bulletDamage = bullet.AddComponent <DamageSystem>(); } DamageSystem weaponDamage = this.GetComponent <DamageSystem>(); if (weaponDamage != null) { // the bullet inherits the damage properties from the gun that fired it bulletDamage.Inherit(weaponDamage); } bulletDamage.destroyAfterDamage = true; // set the bullet to spawn as a child of the gun bullet.transform.position = transform.position; if (circleSpray) { // create circular spray by rotating by _halfSpray to the side and then spinning it a random amount. bullet.transform.rotation = transform.rotation * Quaternion.Euler(Random.Range(0.0f, _halfSpray), 0.0f, Random.Range(0.0f, 360.0f)); } else { // flat spray (good for the player, since a circle spray makes them shoot the ground). // pick a random rotation between -_halfSpray and _halfSpray. bullet.transform.rotation = transform.rotation * Quaternion.Euler(0.0f, Random.Range(-_halfSpray, _halfSpray), 0.0f); Vector3 bulletRot = bullet.transform.eulerAngles; bulletRot.x = 0f; bullet.transform.eulerAngles = bulletRot; } // make that shit go forward Projectile projectile = bullet.GetComponent <Projectile>(); bullet.rigidbody.velocity = bullet.transform.forward * projectile.speed; }