- Home /
Disabling/Enabling Different Character Controllers.
Greetings. I sorted all my problems, now down to my last one for basic gameplay. I have two gun scripts attached my player and I want to enable and disable one vice versa. (Different weapons)
Is this possible? I just am unsure on how to go about it.
Getbuttondown pistol enable pistolscript disable othergunscript. disable ajbfag disable aofbhaobgh disable aofoafa
getbuttondown othergun enable othergunscript disable pistolscript disable ajbfag disable aofbhaobgh disable aofoafa
and so on with other buttons.... enabling and disabling the rest.
I know it is a lot more complex than that but instead of me trying to write one with my limited knowledge on calling and disabling scripts I know I would end up being wrong and coming here.
I know that isint code but that is the sort of thing I want.
Preferably C# but I could probably try to convert it if it is done in Java.
Sorry, quite confused by what your asking. Do you have 5 different guns and you want to change between them after pressing 1, 2, 3, 4, 5 or 'scroll through' your guns by pressing 1 each time
It is only two guns currently, the rest were to help understand what I plan on doing once I get the basics of my game down. I the keys will be in a 1,2,3,4..... sort of thing, each key for a different gun
Answer by Uriel_96 · Dec 11, 2010 at 03:24 PM
OK this is a little different but it may works. OK so first add an empty object and parent the weapons in the empty object. Then put this script in the player.
var weapons : Transform;
var weapon1 : Transform;
var weapon2 : Transform;
var weapon3 : Transform;
var weapon4 : Transform;
function Update(){
if(Input.GetKeyDown("1")){
weapons.SetActiveRecursively(false);
weapon1.SetActiveRecursively(true);
}
//and there you can continue and continue
}
in the variable weapons put the empty object and in the weapon1,2,3,4 put the weapons
$$anonymous$$ I gave that a go. $$anonymous$$y Player is everything. aside from what the bullets do. THe player contains all the ammo in it's controller script. (The game is 2d). I duplicated the player for testing reasons and did it under the code you gave. It worked by me only controlling one player. And I could switch between them. I did come across two problems though the other play stayed where I spawned or was last using and didn't follow the player I was controlling. And the monsters still chased after it and could damage it. I need it to be invisible and follow me so I can just change weapon if you get me.
sorry, I dont understand, your problem is that it dosent work for 2 players or what????
and sorry I do it in java but I did not read that part :(
Your answer
![](https://koobas.hobune.stream/wayback/20220613090620im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Disable a script from another script 2 Answers
switch scripts? 1 Answer
enable/disable specific components 3 Answers
Another Java to C# Conversion Question!! 1 Answer
Disable & Re-enable Script 1 Answer