Number of stars


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 **

This is the code for the stars

public class Stars : MonoBehaviour {

	public static int stars;
	public static int allstars;
	public Image[] starphoto;
	public Sprite fullstar;
	public Sprite emptystar;

	void Start(){
		stars = stars;
		allstars = 3 ;

	void Update(){
		if(stars > allstars){
			stars = allstars;
		for (int i = 0; i < starphoto.Length; i++){
			if (i < stars){
				starphoto*.sprite = fullstar;*
  •  	} else {*

_ starphoto*.sprite = emptystar;_

* if (i < allstars){*
_ starphoto*.enabled = true;
} else {
starphoto.enabled = false;

This code works for the stars, I want to see the stars in every world underneath the world, how it is done?

Change the int all stars to an array of ints, since you need to compare the amount of stars per level, you will need to add the stars value depending in the current scenebuildindex and just iterate over the array for displaying the stars

before you get to crazy on trying to recode anything, 1 problem that may be preventing you from showing the running tally of stars accrued is that your statement

stars = allstars

is backwards.

so your stars = stars is fine, allstars = 3 is fine but in the update method what’s happening is you are equating stars to allstars anytime stars is greater than allstars, so its resetting the displayed int back at 3 everytime. the simple fix would be allstars = stars.

obviously in math on paper A = B is the same as B = A but in coding what’s happening is that it reads the first variable and equates it to the second rather than making which ever is higher the master variable.

let me know if that works, if not there may be a few other things to add that I think may make it work