How can i get the value of the Scrpit what is attached on the Image
Hi guys, i usual try to solve my problems with lots of trying thinking and searching before i come here.
I want the player to be able to just play one level after another.
Following Problem:
I have a nice Swipe LevelSelect Scene, 10 Levels, every Level has an Image and swipes into a Selector to detect the name of the level. Now i attached a simple script to all images, its called currenLevel.
public int currentLevel; (thats all what the script consist of)
After attaching it to all 10 images, i can give every image a value in the inspector.
like 1,2,3 and so on.
In my LoadManager what is attached to the detecting selector, i want to compare this value with the saved value(PlayerPref).
But it doesnt work, it always gives me the number 5.
Maby its really simple but i cant get the value from the currentLevel script into the Loadmanager Script. I am also using a get Method in the CollisionTrigger Method, so when the picture hits the selector it gives me the value, well thats what i thought. I mean it gives me the LevelName in the concole, thats works fine. Sorry my code is german/english mixed.
Here the LoadManager Script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class LoadManager : MonoBehaviour { private string LevelChoice; private int AktuellesLevel; public AktuellelLevel AL; private int LevelValue;
 // Start is called before the first frame update
 private void Start()
 {
     AL = FindObjectOfType<AktuellelLevel>();
     AktuellesLevel = PlayerPrefs.GetInt("farthestLevel");
   
 }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(1))
     {
         Select();
     }
 }
 public void Select()
 {
    
     
     SceneManager.LoadScene(LevelChoice);
     
 }
 public void OnTriggerEnter2D(Collider2D collision)
 {
   
     LevelChoice = collision.name;
     GetLevelValue();
     Debug.Log(LevelValue);
     Debug.Log(LevelChoice);
     
 }
 
 public void Hauptmeue()
 {
     SceneManager.LoadScene(0);
 }
 public void GetLevelValue()
 {
     LevelValue = AL.Level;
 }
   
}
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                