Advertisement
nutter666

TileSpawner

Sep 24th, 2021
1,483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TileSpawner : MonoBehaviour
  6. {
  7.     private List<int> testBlueprint;
  8.     public string currentTileset = "dirt";
  9.  
  10.     private float startX = -8.5f;
  11.     private float startY = 0;
  12.     private float tileSize = 1f;
  13.  
  14.     public GameObject tilePrefab;
  15.  
  16.     private void Awake()
  17.     {
  18.         testBlueprint = new List<int> { 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 14 };
  19.     }
  20.  
  21.     // Start is called before the first frame update
  22.     void Start()
  23.     {
  24.         generateRow("dirt", testBlueprint);  
  25.     }
  26.  
  27.     public void generateRow(string currentTileset, List<int> blueprint)
  28.     {
  29.         for (int i = 0; i < blueprint.Count; i++) {
  30.             GameObject t = Instantiate(tilePrefab, new Vector2(startX + (tileSize *i), startY), Quaternion.identity);
  31.             t.GetComponent<TileController>().initTile(currentTileset, blueprint[i]);
  32.         }
  33.     }
  34.  
  35.     // Update is called once per frame
  36.     void Update()
  37.     {
  38.        
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement