Level Selection Menu with Stars & Level Unlocking | Unity Beginner Tutorial
HTML-код
- Опубликовано: 22 май 2024
- Level Selection Menus are an extremely part of most games, allowing user to choose what the want to play in your game
In this Unity tutorial we'll make a complete level selection menu, with all the required code for starting levels, unlocking levels and giving stars to levels.
Cartoon Game UI Pack Asset used in this tutorial:
assetstore.unity.com/packages...
Thank you for the video, it was of great help to me. I had to make some changes for my game but the scroll view was the best thing I learned how to use, now I can make as many levels as I want!
Keep up good work
Of course, I had to make small changes to the code, but thanks a lot anyway.
download pls
its not working, when you click on the first level and complete it you are not unlocking the next the interactable stays false
Fixed it :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelSelectMenu : MonoBehaviour
{
public LevelObject[] levelObjects;
public static int currLevel;
public static int UnlockedLevels;
public void OnClickLevel(int levelNum)
{
currLevel = levelNum;
SceneManager.LoadScene("GameScene");
}
public void OnClickBack()
{
this.gameObject.SetActive(false);
}
// Start is called before the first frame update
void Start()
{
UnlockedLevels = PlayerPrefs.GetInt("UnlockedLevels", 1); // Pierwszy poziom odblokowany na starcie
for (int i = 0; i < levelObjects.Length; i++)
{
if (UnlockedLevels > i)
{
levelObjects[i].levelButton.interactable = true;
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelComplete : MonoBehaviour
{
public void OnLevelComplete()
{
if (LevelSelectMenu.currLevel == LevelSelectMenu.UnlockedLevels)
{
LevelSelectMenu.UnlockedLevels++;
PlayerPrefs.SetInt("UnlockedLevels", LevelSelectMenu.UnlockedLevels);
}
SceneManager.LoadScene("MainMenu");
}
}