# problem when changing weapon

**URL:** https://discussions.unity.com/t/problem-when-changing-weapon/611948
**Category:** Scripting
**Tags:** Scripting
**Created:** [January 9, 2016, 3:44pm UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948 "2016-01-09T15:44:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dstaroski](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@dstaroski](https://discussions.unity.com/u/dstaroski)
#### Post date: [January 9, 2016, 3:44pm UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948/1 "2016-01-09T15:44:07Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Beef331\_1](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@Beef331\_1](https://discussions.unity.com/u/Beef331_1)
#### Post date: [January 10, 2016, 8:28am UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948/2 "2016-01-10T08:28:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dstaroski](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@dstaroski](https://discussions.unity.com/u/dstaroski)
#### Post date: [January 10, 2016, 12:02pm UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948/3 "2016-01-10T12:02:10Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Fearleas](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@Fearleas](https://discussions.unity.com/u/Fearleas)
#### Post date: [January 10, 2016, 2:31pm UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948/4 "2016-01-10T14:31:27Z")

</div>

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](http://answers.unity3d.com/questions/353475/setactiverecursively-is-now-obsolete-in-unity-40.html)).  
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.

---

<div class="post-metadata">

### Author: ![dstaroski](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@dstaroski](https://discussions.unity.com/u/dstaroski)
#### Post date: [January 10, 2016, 8:15pm UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948/5 "2016-01-10T20:15:46Z")

</div>

ok, sorry my english, I am Brazilian, 🙂  
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.

 ![2458001--168985--1.jpg](https://europe1.discourse-cdn.com/unity/original/3X/a/0/a0c107fd53598856336dff79c9c82580da8f29c6.jpeg)  
 ![2458001--168986--2.jpg](https://europe1.discourse-cdn.com/unity/original/4X/a/b/b/abb31fe589d6b5af6e2bde7c46711be1e324f243.jpeg)  
 ![2458001--168987--3.jpg](https://europe1.discourse-cdn.com/unity/original/3X/f/5/f545e60e839167e396a6953d750f4a9ff4946e13.jpeg)

---

<div class="post-metadata">

### Author: ![Fearleas](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@Fearleas](https://discussions.unity.com/u/Fearleas)
#### Post date: [January 24, 2016, 6:12pm UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948/6 "2016-01-24T18:12:21Z")

</div>

Did you already fix your problem?

---

<div class="post-metadata">

### Author: ![dstaroski](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@dstaroski](https://discussions.unity.com/u/dstaroski)
#### Post date: [January 26, 2016, 5:43pm UTC](https://discussions.unity.com/t/problem-when-changing-weapon/611948/7 "2016-01-26T17:43:01Z")

</div>

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