Untitled

 avatar
unknown
plain_text
3 months ago
497 B
8
Indexable
using UnityEngine;

public class PlayerShoot : MonoBehaviour
{
    public GameObject bullet;
    public Transform firePoint;
    public float bulletSpeed = 20f;

    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Shoot();
        }
    }

    void Shoot()
    {
        GameObject b = Instantiate(bullet, firePoint.position, firePoint.rotation);
        Rigidbody rb = b.GetComponent<Rigidbody>();
        rb.velocity = firePoint.forward * bulletSpeed;
    }
}
Editor is loading...
Leave a Comment