Untitled
unknown
plain_text
a year ago
580 B
9
Indexable
public class PlayerShooting : MonoBehaviour
{
public GameObject bulletPrefab;
public Transform bulletSpawn;
public float bulletSpeed = 20f;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
GameObject bullet = Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
Rigidbody rb = bullet.GetComponent<Rigidbody>();
rb.velocity = bulletSpawn.forward * bulletSpeed;
Destroy(bullet, 2f); // Destroy the bullet after 2 seconds
}
}Editor is loading...
Leave a Comment