if else statement ignored ??

I’ve been up for too long already and I need some fresh eyes to look at this simple snippet of code and see if I am doing anything too stupid here.

First off let me explain what I am trying to accomplish. I am making a simple temple run type endless running game and am just in the preliminary stages of figuring some mechanics out. What I am doing right now is moving cubes representing the ground you are running on to just past the screen view. Once the cube reaches this point a random number is called and if the number is 0 it will make the cube transparent and stop the physics on the cube so that the player can fall through it.

The problem I am having is that Unity will apparently ignore my if else logic preventing the creation of two transparent blocks at once.

This is a problem since my “player” can’t jump two spaces at once.
Here is the if else statement.

if (transform.position.z < 0)
	{
		rnd = Random.Range(0, 5);
		if(rnd == 0)
		{
			if(madeHole == false)
			{
				renderer.enabled = false;
				collider.isTrigger = true;
				madeHole = true;
			}
			else
			{
				renderer.enabled = true;
				collider.isTrigger = false;
				madeHole = false;
			}
		}
		else
		{
			renderer.enabled = true;
			collider.isTrigger = false;
			madeHole = false;
		}
		
		transform.position.z += 150;
	}

Any help or insight could be useful. Thank you.

First of all,

you can be utterly certain that there is NO problem with the if statement in Javascript, Mono or Unity3D.

You’ve made some mistake.

Add debugging statements:

Debug.Log("I am here, point A");

and for example …

Debug.Log("Now the value of blah is ... " + x );

In this way you can learn more and solve the problem.

When you are learning to program you need to constantly include Debug.Log statements. Essentially every other line of code should be a Debug line.

You’ll have the problem solver within an hour, cheers