- Home /
Issue with switch statement
Hey guys, I seem to be having some trouble with a switch statement I have in javascript. What is supposed to happen is the character gets hit 6 times, and on the 6th time he dies, respawns if there are any lives left.
Now, the problem I am having is on the 6th hit, the life is taken away, the body parts that are supposed to be rendered are rendered, but i am in the same spot, until the character gets hit again. The 7th hit is when the character goes to the respawn point, with a hit on him. I'll post a small portion of the code, but if more is needed, just ask.
Any help would be grateful, thanks guys.
switch(HITS) { case 1: //disable bodypart2 //bodyPart5.renderer.enabled = false; Sphere08.renderer.enabled = false; Sphere14.renderer.enabled = false;
break;
case 2:
//disable bodypart2
Sphere07.renderer.enabled = false;
Sphere13.renderer.enabled = false;
break;
case 3:
//disable bodypart3
Sphere06.renderer.enabled = false;
Sphere12.renderer.enabled = false;
break;
case 4:
//disable bodypart4
Sphere05.renderer.enabled = false;
Sphere11.renderer.enabled = false;
break;
case 5:
//disable bodypart5
Sphere04.renderer.enabled = false;
Sphere10.renderer.enabled = false;
break;
case 6:
//Character is dead, respawn, lose a life, reset body parts
CharacterMove.dead = true;
LIVES -= 1;
HITS = 0;
Sphere08.renderer.enabled = true;
Sphere14.renderer.enabled = true;
Sphere07.renderer.enabled = true;
Sphere13.renderer.enabled = true;
Sphere06.renderer.enabled = true;
Sphere12.renderer.enabled = true;
Sphere05.renderer.enabled = true;
Sphere11.renderer.enabled = true;
Sphere04.renderer.enabled = true;
Sphere10.renderer.enabled = true;
break;
}
.
function LateUpdate() { if (checkPoint.originalSpawn == true) { if(dead) { transform.position = Vector3(40, 1, 17); transform.eulerAngles = Vector3(rotation.x, CharacterMove.rotationy, rotation.z); // rotation dead = false; } }
}
.
function OnTriggerEnter( hit : Collider) { if(hit.gameObject.tag == "fallout") { dead = true; //substract life here HealthControl.LIVES -= 1; }
if(hit.gameObject.tag == "enemyProjectile")
{
//gotHit = true;
HealthControl.HITS += 1;
Destroy(hit.gameObject);
}
}
Definately need more code please - don't be afraid of posting the whole switch statement :)
added the full switch statement for you wibbs, as well as where the character respawn code is located. the checkPoint.originalSpawn code is for check points that are throughout the level and i have tested that code, and it works fine for collisions and all that $$anonymous$$arnix.
also, sorry about the code break for the second line of code which is in a different js script. im still trying to figure these forums out
So, HITS goes up on a bullet, but when does it run that big switch that uses HITS? If it isn't right after adding, there's your problem. A trick is to "play computer" and trace through everything a collision eventually does.
Answer by Paige · Apr 17, 2011 at 04:56 AM
Well, I found the problem. For not very good reasons at all, I chose to make a separate script for handling the player running into checkpoints, and as I was transferring over all the code of that to the main character script, I saw that the respawn scripts were in the OnTriggerEnter function. so, after adding the respawn code to the Update function, all is well. I had a feeling after Owen Reynolds mentioned tracing everything the collision eventually did. Finally I can move on, heh.
Your answer
Follow this Question
Related Questions
Anyone help with my switch statement? 0 Answers
problem with child arrangement script 0 Answers
Using the StartsWith function in a Switch Case Statement 1 Answer
What is wrong with my c# switch statement? 1 Answer
FPS Game - I am making an Aim System and need help (Calling all game scripters) 1 Answer