How to disable a script of my weapon until it is picked up?,How do I disable a script until it is enabl

My script is down below, pretty much when I start up my game and hold down fire1 my gun will still shoot. I want it to be disabled until I pick it up (I’ve already created that in another script

using UnityEngine;

public class GunScript : MonoBehaviour
public float damage = 10f;
public float range = 100f;
public float fireRate = 15f;
public float impactforce = 30f;

public Camera fpsCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;

private float nextTimeToFire = 0f;

// Update is called once per frame
void Update()
    if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
        nextTimeToFire = Time.time + 1f / fireRate;

void Shoot ()

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

        Target target = hit.transform.GetComponent<Target>();
        if (target != null)

        if (hit.rigidbody != null)
            hit.rigidbody.AddForce(-hit.normal * impactforce);

        GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
        Destroy(impactGO, 2f);


You can enable/disable components via script using:

gameObject.GetComponent<GunScript>().enabled = true;