Guest User

Untitled

a guest
Jan 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. //shapes to be spawned
  2. public List<GameObject> shapes;
  3. //shapes that are in game
  4. public List<GameObject> spawnedShape;
  5. //num of next shape to be places
  6. public int next;
  7. //list of shapes that can be spawned
  8. public List<int> shapeCount;
  9. System.Random random;
  10.  
  11.  
  12. void Start()
  13. {
  14. random = new System.Random();
  15. for (int i = 0; i < 4; i++)
  16. {
  17. //adds shapes that can be added into shapecount list.
  18. for(int j = 0; j < 4; j++)
  19. {
  20. shapeCount.Add(i);
  21. }
  22. //load game objects from resources into list
  23. GameObject go = Resources.Load("shape" + i) as GameObject;
  24. shapes.Add(go);
  25. }
  26. //set next shape
  27. int next = setNext();
  28. }
  29.  
  30. void Update()
  31. {
  32. if (Input.GetButton("Fire1")) {
  33. spawnShape();
  34. }
  35. }
  36.  
  37. public int setNext()
  38. {
  39. if (shapeCount.Count != 0)
  40. {
  41. int num = random.Next(0, shapeCount.Count);
  42. return shapeCount[num];
  43. }
  44. else return -1;
  45. }
  46.  
  47. void spawnShape()
  48. {
  49. if(next == -1)
  50. {
  51. Debug.Log("Out of shapes");
  52. }else
  53. {
  54. //creates instance of shape
  55. GameObject go = Instantiate(shapes[next]);
  56. //creates and assigns random x, y coordinate
  57. int x = random.Next(0, 500);
  58. int y = random.Next(0, 500);
  59. go.transform.position = new Vector3(x, y, 0);
  60. spawnedShape.Add(go);
  61. }
  62. //gets colour of next shape
  63. next = setNext();
  64. }
Add Comment
Please, Sign In to add comment