Answers for "gun shoot code"

0

gun shoot code

public float damage = 10f;
    public float range = 100f;


    public Camera fpsCam;
    public ParticleSystem muzzleFlash;
    public GameObject ImpactEffect;

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

        RaycastHit hit;
        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);

        }

        Instantiate(ImpactEffect, hit.point, Quaternion.LookRotation(hit.normal));
    }
Posted by: Guest on April-22-2021

Browse Popular Code Answers by Language