Skip to content

Instantly share code, notes, and snippets.

@mhomol
Created January 4, 2016 20:58
Show Gist options
  • Save mhomol/bf81d58e55083d7b82a3 to your computer and use it in GitHub Desktop.
Save mhomol/bf81d58e55083d7b82a3 to your computer and use it in GitHub Desktop.
Bag Labs Post - 3D Runner - Obstacles
public float speed = 0.1f;
public bool running = true;
private void updateCubePosition(float min, float max, float startZ, string id)
{
GameObject cube1 = GameObject.FindGameObjectWithTag (id);
Vector3 currentPosition = cube1.transform.position;
//Reset the cube's position once it has passed the player
if (cube1.transform.position.z >= 1)
{
currentPosition.z = startZ;
float randomX = Random.Range (min, max);
currentPosition.x = randomX;
//Increase the speed of the cube on the next run
if (id == "Cube1")
{
if (speed <= 0.4)
{
speed += 0.05f;
}
}
}
currentPosition.z = currentPosition.z + speed;
cube1.transform.position = currentPosition;
}
// Update is called once per frame
void Update ()
{
if (running == true)
{
updateCubePosition (-4.0f, 0f, -22, "Cube1");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment