Toggle weapon Script.

“Hola! I have had unity for about 3 months now and and really want to know how I can have a Primary weapon and a Secondary weapon. It would really help if someone could help me out and tell me what I have to do.”

TASNO :smiley:

You can either toggle with one key:

public GameObject gun1;
public GameObject gun2;

void Update() {
     // Sets each gameobject opposite of its current state
     if (Input.GetKeyDown("e")) {
          gun1.SetActive(!gun1.activeSelf);
          gun1.SetActive(!gun1.activeSelf);
     }
}

or two:

void Update() {
     if (Input.GetKey("1")) {
          gun1.SetActive(true);
          gun2.SetActive(false);
     }
     if (Input.GetKey("2")) {
          gun1.SetActive(false);
          gun2.SetActive(true);
     }
}