Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

Use of DontDestroyonLoad()

$
0
0
I need to send a parameter from a scene to another, and I wanted to use DontDestroyonLoad(). But exactly, how can I take this parameter from the script attached to a button that I clicked to pass to next scene? (I tried to use also static variables) Script that contains DontDestroyOnLoad(): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Tunnel : MonoBehaviour { public string levelC; // Use this for initialization void Start() { DontDestroyOnLoad(this.gameObject.GetComponent()); } public string LevelC { get { return levelC; } } } Script that loads informations: using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class LoadInformations : MonoBehaviour { public Text titolo; public Text oro; public Text argento; public Text bronzo; public Text extra; private string filePath = "info.txt"; void Start () { bool i = true; string levelC = GameObject.Find("Tunnel").GetComponent().LevelC; try { string line; StreamReader sr = new StreamReader(filePath, Encoding.Default); using (sr) { line = sr.ReadLine(); do { if (line != null) { string[] words = line.Split(','); if (words.Length > 0) { if (words[0]==levelC) { titolo.text = words[0]+" - "+words[1]; oro.text = words[2]; argento.text = words[3]; bronzo.text = words[4]; extra.text = words[5]; i = false; } } } line = sr.ReadLine(); } while (line == null && i); sr.Close(); } } catch (IOException e) { extra.text = "ERRORE!!! "+e; } } }

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>