- Home /
This question was
closed Oct 21, 2013 at 11:46 PM by
meat5000 for the following reason:
The question is answered, right answer was accepted
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 :D
Comment
Best Answer
Answer by Coreyf716 · Mar 03, 2013 at 05:10 PM
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);
}
}
Anytime :) if you found it helpful please give it a thumbs up and mark it as the answer
Follow this Question
Related Questions
Gun Manager only working once 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a gun shoot 3 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer