UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"shoot bullets randomly"
public class Shooting : MonoBehaviour { [SerializeField] private Transform barrel; [SerializeField] private Rigidbody2D bullet; private float bulletSpeed; private float randomDirection, randomSpeed; public void FireBullets() { for (int i = 0; i <=9; i ) { var newBullet = Instantiate(bullet, barrel.position, barrel.rotation); randomDirection = Random.Range(-0.5f, 0.5f); randomSpeed = Random.Range(100f, 500f); newBullet.AddRelativeForce(new Vector2(0f randomDirection, 1f) * randomSpeed); } } }