Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MapGenerator : MonoBehaviour
- {
- public GameObject grassPrefab;
- public GameObject dirtPrefab;
- public Transform groundFolder;
- private List<int> heights = new List<int>();
- void Start()
- {
- for (int i = 0; i < 30; ++i)
- {
- GameObject grassTile = Instantiate(grassPrefab, groundFolder);
- GameObject dirtTile = Instantiate(dirtPrefab, groundFolder);
- int groundHeight = 0;
- if (i != 0)
- {
- if(heights[i-1] == 0)
- {
- groundHeight = Random.Range(0, 2);
- heights.Add(groundHeight);
- } else if (heights[i - 1] == 1)
- {
- groundHeight = Random.Range(0, 2);
- heights.Add(groundHeight);
- }
- }
- else
- {
- groundHeight = Random.Range(0, 1);
- heights.Add(groundHeight);
- }
- if (groundHeight == 0)
- {
- grassTile.transform.localPosition = new Vector3(-12.725f + i * grassTile.GetComponent<SpriteRenderer>().bounds.size.x, 0, 0);
- }
- else if(groundHeight == 1)
- {
- dirtTile.transform.localPosition = new Vector3(-12.725f + i * grassTile.GetComponent<SpriteRenderer>().bounds.size.x, 0, 0);
- grassTile.transform.localPosition = new Vector3(-12.725f + i * grassTile.GetComponent<SpriteRenderer>().bounds.size.x, grassTile.GetComponent<SpriteRenderer>().bounds.size.y, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement