Advertisement
salahzar

Calcolatrice.cs

Apr 11th, 2021
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6.  
  7. public class Calcolatrice : MonoBehaviour
  8. {
  9.     public string key = "5211";
  10.     public string entered = "0";
  11.     public Text displayText;
  12.     public void ButtonClicked()
  13.     {
  14.         string bottone = EventSystem.current.currentSelectedGameObject.name;
  15.         Debug.Log(bottone);
  16.         switch (bottone)
  17.         {
  18.             case "Clear":
  19.                 entered = "";
  20.                 break;
  21.             case "OK":
  22.                 if(entered == key)
  23.                 {
  24.                    entered = "Esatto";
  25.                 } else
  26.                 {
  27.                    entered = "Sbagliato";
  28.                 }
  29.                 break;
  30.  
  31.             default:
  32.                 int numeroCorrente;
  33.                 int.TryParse(entered, out numeroCorrente);
  34.                 int numeroBottone;
  35.                 int.TryParse(bottone, out numeroBottone);
  36.                 int nuovoValore = numeroCorrente * 10 + numeroBottone;
  37.                 entered = ""+nuovoValore;
  38.                 break;
  39.         }
  40.         displayText.text = entered;
  41.  
  42.  
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement