Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
Great vid! Note: You can replace the if-statement (02:00) by a while loop to handle multiple level ups at once.
Great information. Just wanted to point out that the curve at 03:56 doesn't have the same shape as in 04:17, so the leveling progression won't be as expected.
This is what we need about a tutorial about leveling system, Simple and very effective. Great video.
What I needed. Keep up the good work!
Nice one!
Y-Y is there a script that can script scripts for me
Lmao, copilot
hey i re write your code so that its saveable :P
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using TMPro;public class ExperienceManager : MonoBehaviour{ [Header("Experience")] [SerializeField] AnimationCurve experienceCurve; int currentLevel, totalExperience; int previousLevelsExperience, nextLevelsExperience; [Header("Interface")] [SerializeField] TextMeshProUGUI levelText; [SerializeField] TextMeshProUGUI experienceText; [SerializeField] Image experienceFill; void Start() { UpdateLevel(); totalExperience = PlayerPrefs.GetInt("totalExperience"); currentLevel = PlayerPrefs.GetInt("currentLevel"); previousLevelsExperience = PlayerPrefs.GetInt("previousLevelsExperience"); nextLevelsExperience = PlayerPrefs.GetInt("nextLevelsExperience"); } void Update() { experienceText.text = " " + totalExperience.ToString(); PlayerPrefs.SetInt("totalExperience", totalExperience); levelText.text = " " + currentLevel.ToString(); PlayerPrefs.SetInt("currentLevel", currentLevel); previousLevelsExperience.ToString(); PlayerPrefs.SetInt("previousLevelsExperience", previousLevelsExperience); nextLevelsExperience.ToString(); PlayerPrefs.SetInt("nextLevelsExperience", nextLevelsExperience); CheckForLevelUp(); UpdateInterface(); if (Input.GetMouseButtonDown(0)) { AddExperience(5); } } public void AddExperience(int amount) { totalExperience += amount; CheckForLevelUp(); UpdateInterface(); } void CheckForLevelUp() { if(totalExperience >= nextLevelsExperience) { currentLevel++; UpdateLevel(); // Start level up sequence... Possibly vfx? } } void UpdateLevel() { previousLevelsExperience = (int)experienceCurve.Evaluate(currentLevel); nextLevelsExperience = (int)experienceCurve.Evaluate(currentLevel + 1); UpdateInterface(); } void UpdateInterface() { int start = totalExperience - previousLevelsExperience; int end = nextLevelsExperience - previousLevelsExperience; levelText.text = currentLevel.ToString(); experienceText.text = start + " exp / " + end + " exp"; experienceFill.fillAmount = (float)start / (float)end; }}
Great vid!
Note: You can replace the if-statement (02:00) by a while loop to handle multiple level ups at once.
Great information. Just wanted to point out that the curve at 03:56 doesn't have the same shape as in 04:17, so the leveling progression won't be as expected.
This is what we need about a tutorial about leveling system, Simple and very effective. Great video.
What I needed. Keep up the good work!
Nice one!
Y-Y is there a script that can script scripts for me
Lmao, copilot
hey i re write your code so that its saveable :P
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ExperienceManager : MonoBehaviour
{
[Header("Experience")]
[SerializeField] AnimationCurve experienceCurve;
int currentLevel, totalExperience;
int previousLevelsExperience, nextLevelsExperience;
[Header("Interface")]
[SerializeField] TextMeshProUGUI levelText;
[SerializeField] TextMeshProUGUI experienceText;
[SerializeField] Image experienceFill;
void Start()
{
UpdateLevel();
totalExperience = PlayerPrefs.GetInt("totalExperience");
currentLevel = PlayerPrefs.GetInt("currentLevel");
previousLevelsExperience = PlayerPrefs.GetInt("previousLevelsExperience");
nextLevelsExperience = PlayerPrefs.GetInt("nextLevelsExperience");
}
void Update()
{
experienceText.text = " " + totalExperience.ToString();
PlayerPrefs.SetInt("totalExperience", totalExperience);
levelText.text = " " + currentLevel.ToString();
PlayerPrefs.SetInt("currentLevel", currentLevel);
previousLevelsExperience.ToString();
PlayerPrefs.SetInt("previousLevelsExperience", previousLevelsExperience);
nextLevelsExperience.ToString();
PlayerPrefs.SetInt("nextLevelsExperience", nextLevelsExperience);
CheckForLevelUp();
UpdateInterface();
if (Input.GetMouseButtonDown(0))
{
AddExperience(5);
}
}
public void AddExperience(int amount)
{
totalExperience += amount;
CheckForLevelUp();
UpdateInterface();
}
void CheckForLevelUp()
{
if(totalExperience >= nextLevelsExperience)
{
currentLevel++;
UpdateLevel();
// Start level up sequence... Possibly vfx?
}
}
void UpdateLevel()
{
previousLevelsExperience = (int)experienceCurve.Evaluate(currentLevel);
nextLevelsExperience = (int)experienceCurve.Evaluate(currentLevel + 1);
UpdateInterface();
}
void UpdateInterface()
{
int start = totalExperience - previousLevelsExperience;
int end = nextLevelsExperience - previousLevelsExperience;
levelText.text = currentLevel.ToString();
experienceText.text = start + " exp / " + end + " exp";
experienceFill.fillAmount = (float)start / (float)end;
}
}