Advertisement
drakon-firestone

Untitled

Dec 6th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LevelGenerator : MonoBehaviour
  6. {
  7. [SerializeField] private Texture2D map;
  8.  
  9. [SerializeField] private ColorToPrefab[] colorMappings;
  10.  
  11. [SerializeField] private float offset = 5f;
  12.  
  13.  
  14. private void GenerateTile(int x, int z)
  15. {
  16. Color pixelColor = map.GetPixel(x, z);
  17.  
  18. if (pixelColor.a == 0)
  19. return;
  20.  
  21. foreach(ColorToPrefab mapping in colorMappings)
  22. {
  23. if (mapping.color.Equals(pixelColor))
  24. {
  25. Vector3 position = new Vector3(x, 0, z) * offset;
  26. Instantiate(mapping.prefab, position, Quaternion.identity, transform);
  27. break;
  28. }
  29. }
  30.  
  31. }
  32.  
  33. public void GenerateLabirynth()
  34. {
  35. for (int x = 0; x < map.width; x++)
  36. {
  37. for (int z = 0; z < map.height; z++)
  38. {
  39. GenerateTile(x, z);
  40. }
  41. }
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement