Hey guys, I’m messing with this script and can’t get it to work:
// The effect that comes during casting time, not the spell fired
var castParticle : Transform;
// Put the name of the specific spell to make it print in the cast bar
var spellName = "";
var boxRect = 100;
static var castMax = 200;
private static var castNow : int = 0; // Dont mess with that
private var castingSpell = false;
var callCastingMSG = false;
function Update(){
if(Input.GetMouseButtonDown(1) castingSpell == false){
castingSpell = true;
}
else if(Input.GetMouseButtonDown(1) castingSpell == true){
callCastingMSG = true;
}
if(castingSpell == true){
CastFunction();
}
}
function OnGUI () {
GUI.Box(Rect (10, 10, boxRect, 30), "Health: " + boxRect);
if(callCastingMSG == true){
CastingSpellMSG();
}
if(castingSpell == true){
MakeGUI();
}
}
function OnMouseEnter(){
boxRect -= 10;
}
function CastFunction(){
var instantiated = false;
if(instantiated == false){
var instParticle = Instantiate(castParticle, transform.position, transform.rotation);
instantited = true;
}
while (castNow<castMax){
yield WaitForSeconds(0.1);
castNow++;
}
if (castNow == castMax){
castingSpell = false;
castNow = 0;
if(instantiated == true)
Destroy(instParticle.gameObject);
}
}
function CastingSpellMSG(){
GUI.Label(Rect (50, 10, 100, 100), "Already Casting Spell");
yield WaitForSeconds(1);
callCastingMSG = false;
}
function MakeGUI(){
GUI.Box(Rect (545, 500, 210, 30), "");
GUI.Button(Rect (545, 500, castNow, 20), "");
}
The problem is, in the while loop it waits for 0.1 second, and then executes the rest of the code super fast. I want it to wait for 0.1 second every time the castNow variable is less that castMax.
Plus in the castFunction(), it instantiates “instParticle” like a hundred times and never deletes it - I only want it to be instantiated 1 time and then it should be deleted whenever the casting time is over.
Hope you can help me out here ![]()
edit that boxRect is just some health thing I played with ![]()