problem when changing weapon

Good afternoon everyone!
Would I like some assistance, since not yet found a solution. I have a simple script to exchange weapons, the bug is that when for example my AK47 this reloading and if I push the button to switch the weapon he return, but the return to AK47 she gets frozen animation, as if interrupted the animation recharge. I am a beginner and I use the Java language.

Thank you!

Post the script, and Ill see if I can help.

1 Like

ok. script selection weapons:
#pragma strict
function Start () {
}
function Update () {
if(Input.GetKeyDown(“1”)){
selecionararma(0);
}
if(Input.GetKeyDown(“2”)){
if(Inventario_gerais.ak47 == true){
selecionararma(1);
}
}
}
function selecionararma (index : int){
for (var i = 0;i<transform.childCount;i++){
if (i == index)
transform.GetChild(i).gameObject.SetActiveRecursively(false);
else
transform.GetChild(i).gameObject.SetActiveRecursively(true);
}
}

you want me to post the script of weapons?

First of all try using SetActice instead of SetActiveRecursively(because I think it was oboslete SetActiveRecursively is now obsolete in Unity 4.0 - Questions & Answers - Unity Discussions).
I am not sure if it is gonna work but maybe explain better what happened because I don’t understand what you are saying. Or send a gif or video if can’t explain it good enough via text.

1 Like

ok, sorry my english, I am Brazilian, :slight_smile:
the first photo, I have the gun 1, or hands, they are enabled by default. In image 2, I got the gun 2, ak 47. When will recharge it and while this recharging, change for the gun 1, or hands again, which makes the return to Weapon 2 (AK47) the animation stay with error as the image 3.



Did you already fix your problem?

Sorry about the delay my friend, can do. Insert Boolean logic for this and it worked, thanks!