- Home /
disable all weapons for 5 seconds
hello. im having some problems with this script. when i press 2 it disables all the scripts. can anyone tell me how to change it so that it only disables the scripts for 5 seconds.
var spell :Transform;
var health : Transform;
function Update () { if(Input.GetButtonDown("cast")) { var bullit = Instantiate(spell, GameObject.Find("castpoint").transform.position, Quaternion.identity); bullit.rigidbody.AddForce(transform.forward * 1000); }
else if(Input.GetButtonDown("cast2")) { //here, when i press 2 it spawns a prefab (health particle system) var healthskill = Instantiate(health, GameObject.Find("health cast").transform.position, Quaternion.identity); Die();
}
}
function Die () { //if (die) //AudioSource.PlayClipAtPoint(die, transform.position);
// Disable all script behaviours (Essentially deactivating player control) var coms : Component[] = GetComponentsInChildren(MonoBehaviour); for (var b in coms) { var p : MonoBehaviour = b as MonoBehaviour; if (p) p.enabled = false; }
//LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 2.0);
}
Answer by spinaljack · May 23, 2010 at 04:12 PM
Don't disable the script, it's much easier to put a second condition in the attack logic i.e.
if(Input.GetButtonDown("cast2") && canShoot == true){
startTime = Time.time;
canShoot = false;
// other stuff
}
Then you can set canShoot back to true after 5 seconds of being active with a counter e.g.
if(!canShoot){
if(Time.time-startTime>resetTime)
canShoot = true;
}
well that did not work. it said (unknown identifier canshoot or something ) then again it said the same thing for the reset time
obviously you need to declare the variable like all other variables. Just add var canShoot; to the top of the script
var canshoot : boolean;
Please mark that as answered.
perhaps you should be doing some simple beginner program$$anonymous$$g tutorials if you dont know how to create a variable.
Your answer
![](https://koobas.hobune.stream/wayback/20220613020753im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Temporarily disable blayer movement? 1 Answer
deactivate/activate child/separate prefab from script attached to other object 2 Answers
Activate one canvas and deactivating the other. 1 Answer
Why might a pointlight not come back on when re-enabled after being disabled? 1 Answer
Function On GUI 2 Answers