Friday, May 9, 2014

Simple Platformer Day 4

Day 4: 
Thanks to Herbie Piland for the fantastic teaching session in lists.


Figured out the first bit of the spawning pick-up puzzle: picking randomized yet pre-determined positions.

yay!  Just a console message now but so happy :)


Next up: 
  • Figure out how to spawn objects using that coordinate.
  • Bonus: randomly pick from 3 objects.
  • Make pick-up disappear on collision with player.
Learned stuff:

For loop:
for (int i = Random.Range(3,6); i>0; i--) {}

Write to debug log:
Debug.Log("hello");

List of Vector2 coordinates:
protected List<Vector2> coordinatePool = new List<Vector2>(new Vector2[]{new Vector2(5.0f,5.0f),new Vector2(10.0f,10.0f)};

Making templist to keep original list intact:
List<Vector2> tempCoordinatePool = new List<Vector2>(coordinatePool);

Picking a random item from the list:
int randomNumber = Random.Range(0,tempCoordinatePool.Count);
Vector2 spawnCoordinate = tempCoordinatePool[randomNumber];


Removing said item from list to prevent duplicate:
tempCoordinatePool.RemoveAt(randomNumber);

No comments:

Post a Comment