Hi Everyone!
This is my very first post here and my very first and very very, primitively basic application written in Unity.
So my application is a cookie fortune application which has two scenes. Clicking on the first scene will go to second scene and show a fortune sentence. The sentences are stored in an external txt file and a random function will output the random sentence.
So in Unity this code works fine, but when ported to android instead of getting a random sentence I just see the default text (New text).
This is my script for the second scene:
[LIST=1]
[*]public class RandomText : MonoBehaviour {
[*]
[*] public Text myText;
[*]
[*] void Start() {
[*]
[*] var myLines = File.ReadAllLines(@"..\FortuneCookie\Assets\quotes.txt");
[*] int lineCount = myLines.Length;
[*]
[*] int myRandomNumber = Random.Range (0,lineCount);
[*] string myQuote = myLines[myRandomNumber];
[*]
[*]
[*] myText.text = myQuote;
[*] }
[*]
[*]}
[/LIST]
There are actually two issues with this script:
-
When run in Unity the random function runs twice and I have an error but the script runs. The erro message is saying:
"NullReferenceException: Object reference not set to an instance of an object
RandomText.Start() (at Assets/RandomText.cs line: 14) Why is the code executed twice and why do I get that error message? -
In Unity it gives a random sentence, when ported to Android I just get the default input text (New text). What am I doing wrong? How can I solve this issue?
Thank you for your help in advance!