Advertisement
evelynshilosky

LoadSlot - Part 25

Nov 15th, 2023
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class LoadSlot : MonoBehaviour
  8. {
  9.     public Button button;
  10.     public TMPro.TextMeshProUGUI buttonText;
  11.  
  12.     public int slotNumber;
  13.  
  14.     private void Awake()
  15.     {
  16.         button = GetComponent<Button>();
  17.         buttonText = transform.Find("Text (TMP)").GetComponent<TextMeshProUGUI>();
  18.     }
  19.  
  20.     private void Update()
  21.     {
  22.         if (SaveManager.Instance.IsSlotEmpty(slotNumber))
  23.         {
  24.             buttonText.text = "";
  25.         }
  26.         else
  27.         {
  28.             buttonText.text = PlayerPrefs.GetString("Slot" + slotNumber + "Description");
  29.         }
  30.     }
  31.  
  32.     private void Start()
  33.     {
  34.         button.onClick.AddListener(() =>
  35.         {
  36.             if (SaveManager.Instance.IsSlotEmpty(slotNumber) == false)
  37.             {
  38.                 SaveManager.Instance.StartLoadedGame(slotNumber);
  39.                 SaveManager.Instance.DeselectButton();
  40.             }
  41.             else
  42.             {
  43.                 // If empty don't do anything
  44.             }
  45.  
  46.  
  47.         });
  48.     }
  49.  
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement