- Home /
variable doesn't change
the actual script is 500+ lines long so here are some parts this is the function for getting hit with a fireball
function FireballHit () {
health -= laserDamage * damageMultiplier * 2.5; //damage
if(blocking == 0){ //if not blocking
Instantiate(laserHitSound,transform.position,transform.rotation); //play a sound
hit = 1; //character is hit
transform.Rotate(Vector3.right * -20); //rotate backwards to make it look better
Destroy(shownMesh);// destroy the current mesh
shownMesh = Instantiate(hitMesh,transform.position,transform.rotation); // create a
//different mesh
Invoke("Unhit",3);//stop being hit (hit = 0;)
}
}
all the attacks have if(hit == 0){ at the start when the character is hit, hit doesn't change from 0, does anyone know the problem?
Answer by MountDoomTeam · Oct 07, 2012 at 05:43 AM
put a print(hit); straight after your hit command. and also print("hit line 20"); etc every time ; and copy those 2 lines about 10 times down the code, so that when you play you see what happens to hit, where it changes and changes back. i had an error like that and in the end i had left a variable change outside of the loop i thought it was in.
Your answer
Follow this Question
Related Questions
In a function, how do I access a variable of another function in the SAME script? (js) 1 Answer
iTween - calling functions on oncomplete doesn't work if the function is declared as a variable 1 Answer
Weapon script 0 Answers
Is it possible to save a transform.position in a single variable? 1 Answer
How to correctly send a variable to another function? 1 Answer