- Home /
Question by
cosmo_snow · Apr 03, 2014 at 12:33 PM ·
disableenable
How to fix jarring glitch when enabling/disabling object
A small group of us who are new to coding ext are having an issue with our simple fighting game. When we are trying to stop the colliders attach to the weapon disable (By disabling the whole weapon for now) with the following script the weapon bugs out if the keys are pressed in succession then breaks down after so many clicks. Script is in Java but we have the ability to convert to C# of needed.
`#pragma strict
var Attack : GameObject;
function Start () {
Attack.SetActive(false);
}
function Update() {
if(Input.GetKey("[1]"))
If();
else if(Input.GetKey("[2]"))
If();
else if (Input.GetKey("[3]"))
If();
}
function If (){
Debug.Log ("Test");
Attack.SetActive(true);
yield WaitForSeconds (3);
Attack.SetActive(false);
}
`
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613141839im_/https://answers.unity.com/themes/thub/images/avi.jpg)