nutter666

Tiile Controller

Sep 24th, 2021 (edited)
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TileController : MonoBehaviour
  6. {
  7.  
  8.     public SpriteRenderer spriteRenderer;
  9.  
  10.     public Sprite[] dirtTiles;
  11.     public Sprite[] fossilTiles;
  12.     public Sprite[] rockTiles;
  13.     // store your sprites in these
  14.  
  15.  
  16.     private string tileSet;
  17.     private int tileNumber;
  18.  
  19.     public void initTile(string tSet, int tNum){
  20.         this.tileSet = tSet;
  21.         this.tileNumber = tNum;
  22.  
  23.         this.spriteRenderer.sprite = getTileAppearance();
  24.  
  25.     }
  26.  
  27.  
  28.     private Sprite getTileAppearance()
  29.     {
  30.  
  31.         switch (tileSet)
  32.         {
  33.             case "dirt":
  34.                 return dirtTiles[tileNumber];
  35.  
  36.  
  37.             case "fossil":
  38.                 return fossilTiles[tileNumber];
  39.  
  40.  
  41.  
  42.             case "rock":
  43.                 return rockTiles[tileNumber];
  44.  
  45.  
  46.             default:
  47.                 return dirtTiles[tileNumber];
  48.         }
  49.     }
  50.  
  51.         // Start is called before the first frame update
  52.         void Start()
  53.     {
  54.        
  55.     }
  56.  
  57.     // Update is called once per frame
  58.     void Update()
  59.     {
  60.        
  61.     }
  62. }
Add Comment
Please, Sign In to add comment