Home > Enterprise >  I want to add bullets to my code , in unity
I want to add bullets to my code , in unity

Time:09-11

here is my code for the ray cast but I can't add bullets following YouTube videos and my code is working fine so if anyone knows how to add bullets for my code pls let me know it would be very helpful of you.

my code

using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

public class gunFire : MonoBehaviour
{
    public float damage = 12f;
    public float range = 120f;

    public Camera fpsCamera;
    

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            shoot();
        }
        
    }

    void shoot()
    {
        RaycastHit hit;
        if (Physics.Raycast(fpsCamera.transform.position,fpsCamera.transform.forward,out hit,range))
        {
            Debug.Log(hit.transform.name);
            
        }
        
    }
}

CodePudding user response:

I would use unity's particle system to do this and start a particle system when you fire. There should be no need for any raycasting.

  • Related