Hello
I finally could solve my problem with playerpref, but now i have a new problem.
I have the playerpref value and want to compare it with the value i put on every "LevelImage".
But as soon i click for example on Level 3 it changes the value 4 to 7. i put everthing into the console so i can see whats happening with my values.
here are the two scripts.
public class AktuellesLevel : MonoBehaviour
{
public int Level;
// Start is called before the first frame update
void Start()
{
Level = GetComponent().Level;
}
// Update is called once per frame
void Update()
{
}
public void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log(Level);
}
}
And here the second
public class LoadManager : MonoBehaviour
{
private string LevelChoice;
private AktuellesLevel AL;
public int aktuellesLevel;
// Start is called before the first frame update
private void Start()
{
AL = FindObjectOfType();
aktuellesLevel = PlayerPrefs.GetInt("farthestLevel");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(1))
{
if (AktuellesLevel > AL.Level)
{
Select();
}
else
{
Debug.Log("Vorheriges Level noch nicht abgeschlossen");
}
}
}
public void Select()
{
Debug.Log(AL.Level);
Debug.Log(AktuellesLevel);
SceneManager.LoadScene(LevelChoice);
}
public void OnTriggerEnter2D(Collider2D collision)
{
LevelChoice = collision.name;
}
public void Hauptmeue()
{
SceneManager.LoadScene(0);
}
In the second script i shouldt even be able to choose level3 but it is still loading. And after loading
the value AL.Level is 7, not 4 how i set it in the inspector.
I hope someone can help me. I try for a long time now to make to player play each level after another, i seems really complicated to me.
Thanks
↧