StageController.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class StageController : MonoBehaviour {
  5. public static StageController instance;
  6. [SerializeField]
  7. private GameObject[] stage;
  8. private List<GameObject> currMap = new List<GameObject>();
  9. void Awake () {
  10. if (instance) Destroy(gameObject);
  11. else instance = this;
  12. for(int i = 0; i < stage.Length; i++)
  13. {
  14. currMap.Add(Instantiate(stage[i], new Vector3(i * 100, 0, 0), Quaternion.identity) as GameObject);
  15. }
  16. }
  17. public void mapMoveStart()
  18. {
  19. StartCoroutine(mapMove());
  20. }
  21. IEnumerator mapMove()
  22. {
  23. while (true)
  24. {
  25. currMap.ForEach(map => map.transform.position += new Vector3(-0.01f, 0, 0));
  26. yield return new WaitForFixedUpdate();
  27. }
  28. }
  29. public void MapReset()
  30. {
  31. for(int i = 0; i < currMap.Count; i++)
  32. {
  33. Destroy(currMap[i]);
  34. }
  35. currMap.Clear();
  36. for (int i = 0; i < stage.Length; i++)
  37. {
  38. currMap.Add(Instantiate(stage[i], new Vector3(i * 100, 0, 0), Quaternion.identity) as GameObject);
  39. }
  40. }
  41. public void mapStop()
  42. {
  43. StopAllCoroutines();
  44. }
  45. public void mapUpdate()
  46. {
  47. Destroy(currMap[0]);
  48. currMap.RemoveAt(0);
  49. currMap.Add(Instantiate(stage[1], currMap[0].transform.position + new Vector3(100, 0, 0), Quaternion.identity) as GameObject);
  50. }
  51. }