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 LevelGenerator : MonoBehaviour
- {
- [SerializeField] private Texture2D map;
- [SerializeField] private ColorToPrefab[] colorMappings;
- [SerializeField] private float offset = 5f;
- private void GenerateTile(int x, int z)
- {
- Color pixelColor = map.GetPixel(x, z);
- if (pixelColor.a == 0)
- return;
- foreach(ColorToPrefab mapping in colorMappings)
- {
- if (mapping.color.Equals(pixelColor))
- {
- Vector3 position = new Vector3(x, 0, z) * offset;
- Instantiate(mapping.prefab, position, Quaternion.identity, transform);
- break;
- }
- }
- }
- public void GenerateLabirynth()
- {
- for (int x = 0; x < map.width; x++)
- {
- for (int z = 0; z < map.height; z++)
- {
- GenerateTile(x, z);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement