Answer the question
In order to leave comments, you need to log in
Level menu in the game?
There is a level menu. When you click on the level button, you are transferred to the level itself. The idea is that all level buttons are initially gray and only when the player has already visited the level itself does the button turn white. The name of the button in the editor is the number of the level itself, that is, level 1, the name of the button is 1. There is a PlayerPrefs int, called levelNum, it equals the last level the player visited. Wrote this script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class jump : MonoBehaviour
{
public Text puk;//текст который должен становится белым
static bool bol = false;//статическая булевая что бы если levelNum уже не равняется названию кнопки, кнопка оставалась белой
private void Awake()
{
string name = this.gameObject.name;
int num;
int.TryParse(name, out num);//конвертируем название кнопки из string в int
if (num == PlayerPrefs.GetInt("levelNum"))
{
bol = true;
}
if (bol)
{
puk.color = Color.white;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question