using UnityEngine;
public class Shooting : MonoBehaviour
{
public GameObject bulletPrefab;
public Transform gunTransform;
public float bulletSpeed = 20f;
void Update()
{
if (Input.GetButtonDown("Fire1")) // Left mouse click or a specific key
{
ShootBullet();
}
}
void ShootBullet()
{
GameObject bullet = Instantiate(bulletPrefab, gunTransform.position, gunTransform.rotation);
Rigidbody rb = bullet.GetComponent\<Rigidbody\>();
rb.AddForce(gunTransform.forward \* bulletSpeed, ForceMode.Velo
cityChange);
}
}