79513014

Date: 2025-03-16 18:21:31
Score: 0.5
Natty:
Report link

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);

}

}

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Sanjay