Guest User

NumberWizardUI

a guest
Dec 12th, 2019
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5.  
  6. public class NumberWizard : MonoBehaviour
  7. {
  8. [SerializeField] int max;
  9. [SerializeField] int min;
  10. [SerializeField] TextMeshProUGUI guessText;
  11.  
  12. int guess;
  13.  
  14. // Start is called before the first frame update
  15.  
  16. void Start()
  17. {
  18. StartGame();
  19. }
  20.  
  21. void StartGame()
  22. {
  23. NextGuess();
  24. }
  25.  
  26. public void OnPressHigher()
  27. {
  28. min = guess +1;
  29. NextGuess();
  30. }
  31.  
  32. public void OnPressLower()
  33. {
  34. max = guess -1;
  35. NextGuess();
  36. }
  37. void NextGuess()
  38. {
  39. guess = Random.Range(min, max + 1);
  40. guessText.text = guess.ToString();
  41. }
  42. }
RAW Paste Data