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.