EXPERIENCE and LEVELING System | Unity Tutorial

Поделиться
HTML-код
  • Опубликовано: 5 янв 2025

Комментарии • 9

  • @twyxx11
    @twyxx11 9 месяцев назад +2

    Great vid!
    Note: You can replace the if-statement (02:00) by a while loop to handle multiple level ups at once.

  • @DEValen
    @DEValen Год назад +1

    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.

  • @bibliographu
    @bibliographu 5 месяцев назад

    This is what we need about a tutorial about leveling system, Simple and very effective. Great video.

  • @lmao01
    @lmao01 9 месяцев назад

    What I needed. Keep up the good work!

  • @Criwny
    @Criwny Год назад +1

    Nice one!

  • @envieallen7722
    @envieallen7722 4 месяца назад

    Y-Y is there a script that can script scripts for me

  • @OpxGames
    @OpxGames 3 месяца назад

    hey i re write your code so that its saveable :P

    • @OpxGames
      @OpxGames 3 месяца назад

      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;
      }
      }