- Home /
Question by
fizy45 · Feb 15, 2015 at 08:46 PM ·
if-statementsif
Decreasing a value within the if statement !
I am trying to decrease a a value in the if statement but so far all of my attempts are failed.Somehow the value only decreases once.The if statement keeps working forever but the value stays same why.
I am working on a car game and "extra" means the extra health slot.
If player crashes once the extra =1 game continues If player crashes the second time extra =0 now game ends.
void OnCollisionEnter(Collision incoming)
{
incomingName = incoming.collider.name;
if (incomingName.Contains ("Car")) {
if(extra==1)
{
collider.enabled=false;
Destroy(gameObject);
extra =extra-1;
print (extra);
}
else if( !stopGame ) {
transform.GetChild(0).renderer.enabled=true;
SoundController.Static.CarCollisionSound();
UIController.staticInstance.disableIngameScore.SetActive (false);
iTween.MoveTo(UIController.staticInstance.scoreBoard, iTween.Hash ("islocal",true,"position", new Vector3 (0, 0, 0), "time",0.4f,"delay",0.2f,"easetype",iTween.EaseType.easeInOutBack));
CarController.stopGame=true;
UIController.staticInstance.finalScoreCaliculations();
SoundController.Static.backgroundAudio.volume = 0;
incoming.collider.enabled = false;
//incoming.collider.renderer.enabled = false;
//renderer.material.mainTexture = null ;
print ("Game Ended");
}
}
}
Can someone help me on this problem.
Comment
Not much is going to happen after you've destroyed the gameobject.