Abdula_2314124

Untitled

Mar 20th, 2024
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using TMPro;
  2. using UnityEngine;
  3.  
  4. public class ScoreController : MonoBehaviour
  5. {
  6.     [SerializeField] private TextMeshProUGUI scoreText;
  7.     public int Score { get; private set; }
  8.     private void Update()
  9.     {
  10.         if (Input.GetKeyDown(KeyCode.D))
  11.         {
  12.             UpdateScore(2);
  13.         }
  14.         if (Input.GetKey(KeyCode.A))
  15.         {
  16.             UpdateScore(1);
  17.         }
  18.     }
  19.  
  20.     public void UpdateScore(int value)
  21.     {
  22.         Score += value;
  23.         scoreText.text = $"{Score}";
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment