I have the error code of: Error CS0103 The name ‘i’ does not exist in the current context
In the line of code: starsImages_.sprite = starsSprites*;_
In my code of:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LevelSelection : MonoBehaviour
_{_
public bool isUnlocked = false;
public Image lockImage;
public Image[ ] starsImages;
public Sprite[ ] starsSprites;
private void Update()
_{_
UpdateLevelButton();
UnlockLevel();
_}_
private void UnlockLevel()
_{_
int previousLvIndex = int.Parse(gameObject.name) - 1;
if (PlayerPrefs.GetInt(“Lv” + previousLvIndex) > 0)
_{_
isUnlocked = true;
_}_
_}_
private void UpdateLevelButton()
_{_
if (isUnlocked)
_{_
lockImage.gameObject.SetActive(false);
for(int i = 0; i < starsImages.Length; i++)
_{_
_starsImages.gameObject.SetActive(true);
}
for (int i = 0; i < PlayerPrefs.GetInt(“Lv” + gameObject.name); i++);
{
starsImages.sprite = starsSprites;
}
}
else
{
lockImage.gameObject.SetActive(true);
for (int i = 0; i < starsImages.Length; i++)
{_
_starsImages.gameObject.SetActive(false);
}
}
}
}*
and I have no clue why I have the error message because I have been following a tutorial of the same version and I have no clue how to fix it or what’s wrong because I have gone through several times to make sure I did everything perfect and have no misspells or misplaces._
You may think you have gone through the tutorial and verified that your code is correct, but you missed a couple of things.
You have a semicolon on the end of your for loop that should not be there:
for (int i = 0; i < PlayerPrefs.GetInt("Lv" + gameObject.name); i++)[B];[/B]
And the line in the for loop does not make sense:
starsImages.sprite = starsSprites;
starsImages is an array of Sprites, it itself is not a Sprite. You need to access a specific element of the array:
starsImages[i].sprite = starsSprites;
Everything except this semicolon at the end of this line:
for (int i = 0; i < PlayerPrefs.GetInt("Lv" + gameObject.name); i++);