1 скрипт.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class XPMan : MonoBehaviour
{
public TextMeshProUGUI currentXPtext, targetXPtext, levelText;
public int currentXP, targetXP, level;
public static XPMan instance;
private void Awake()
{
if (instance == null)
instance = null;
else
Destroy(gameObject);
}
private void Start()
{
currentXPtext.text = currentXP.ToString();
targetXPtext.text = targetXP.ToString();
levelText.text = level.ToString();
}
public void AddXP(int xp)
{
currentXP += xp;
while (currentXP >= targetXP)
{
currentXP = targetXP - currentXP;
level++;
levelText.text = level.ToString();
}
currentXPtext.text = currentXP.ToString();
}
}
2 скрипт.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PL : MonoBehaviour
{
public void ButtonPressed()
{
Debug.Log("XPMan");
Debug.Log("instanse");
Debug.Log("AddXP");
; XPMan.instance.AddXP(10);
}
}