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 ChunkGen : MonoBehaviour
- {
- [Header("Tiles")]
- public GameObject StoneTile;
- public GameObject tileGold;
- public GameObject tileCoal;
- [Header("Map Stats")]
- public int width;
- public int height;
- [Header("Ores Chances")]
- public float coalChance;
- public float goldChance;
- void Start()
- {
- Generate();
- }
- public void Generate()
- {
- for (int x = 0; x < width; x++)
- {
- for (int y = 0; y < height; y++)
- {
- GameObject tile = Instantiate(StoneTile, Vector3.zero, Quaternion.identity);
- tile.transform.parent = this.transform;
- tile.transform.localPosition = new Vector3(x, y);
- }
- }
- Populate();
- }
- public void Populate()
- {
- foreach(GameObject t in GameObject.FindGameObjectsWithTag("TileStone"))
- {
- float r = Random.Range(0f, 100f);
- GameObject selectedTile = null;
- if (r < goldChance)
- {
- selectedTile = tileGold;
- }
- if (r < coalChance)
- {
- selectedTile = tileCoal;
- }
- if(selectedTile != null)
- {
- GameObject ore = Instantiate(selectedTile, t.transform.position, Quaternion.identity);
- ore.transform.parent = t.transform;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement