- Home /
Level stars on levels menu
Hi!
I want to see the number of stars in the level below every world.
Besides the victory panel, I want to dynamically locate the results of the stars on the levels.
When I win the first level , the same number of stars are shown below the numbers of all the levels.
I want to dynamically see the number of stars in each level
Answer by cs120319992 · Apr 05, 2019 at 11:02 AM
Create array int[] levelStars = new int[10]; // 10 levels with 0 stars
Suppose that 0 - 0 stars, 1 - 1 star, 2 - 2 stars, 3 - 3 stars.
When you pass the level with id = 3, change levelStars[id] = stars count and save it. And in menu load it
I do not understand how to do it
please bring an example
using System;
using System.Collections;
using System.Collections.Generic;
// Script that contains data of levels
public class Levels : $$anonymous$$onobehaviour {
public int[] levelStatus = new int[10]; // Total 10 levels (or use inspector)
/** Let's pretend that
* if levelStatus[0] == -1 { level is closed }
* if levelStatus[0] == 0 { level is not passed or opened }
* if levelStatus[0] == 1 { level is passed on 1 star }
* if levelStatus[0] == 2 { level is passed on 2 stars }
* if levelStatus[0] == 3 { level is passed on 3 stars }
*/
public void LevelOpen(int id) {
levelStatus[id] = 0;
Save();
}
public void LevelPassed(int id, int stars) {
levelStats[id] = stars;
Save();
}
private void Save() {
// Save
}
private void Load() {
}
}
// Script that contains data of current level
public class Levels : $$anonymous$$onobehaviour {
int id = 0; // Level first
float time = 5;
Levels levels;
private Update() {
time -= Time.deltaTime;
}
// When you win
public void LevelPassed() {
if(time > 4) {
levels.levelStatus[id] = 3; // 3 stars
} else
if(time > 3) {
levels.levelStatus[id] = 2; // 2 stars
} else
if(time > 1) {
levels.levelStatus[id] = 1; // 1 stars
} else
if(time > 0) {
levels.levelStatus[id] = 0; // 0 stars
}
}
}
Your answer
Follow this Question
Related Questions
Why this middle code doesnt want to run, Playerpref problem 0 Answers
When I click on 'play' by the main menu, level 1 won't start... How to fix that? 2 Answers
Level is not at 0, 0, 0 after setting the coordinates to 0, 0, 0? 1 Answer
Loading an OBB from a non-google source. 1 Answer
How to load a different prefab using the same scene? 1 Answer