Does your value of number1 come up null or zero in the inspector. If its null try
(eg) if((number1==0) || (number1==null)) { }
(Tip) variables shouldn’t end with numbers in its name. Try something like this - (eg) number0A, or number1A. If you have to parse your value in the future you may get some errors.
There is no error message in the console. It simply does not do anything (neither “positive” or “negative” is displayed).
I’m afraid I don’t quite understand your hint.
Are you saying that what is read from the text file is not really a 0, or at least not understood in the same way? Metaphorically, it’s more like the word zero rather than a number?
It is null (empty). I tried your suggestion, but the effect was no different.
Here’s the full code with your update, for anyone who has similar problems :
import System.IO;
var fileName = "writetest.txt";
var number1 : String;
function Start () {
var sr = new StreamReader(Application.dataPath + "/" + fileName);
var fileContents = sr.ReadToEnd();
sr.Close();
var lines = fileContents.Split("\n"[0]);
number1 = lines[1];
}
function Update() {
//check reads number of second line
if (number1 == "1"){
{
Debug.Log("Positive");
}
}
if (number1 == "0"){
{
Debug.Log("Negative");
}
If you are treating a string as a number it would be more logical to use parseInt to convert it:
var n = parseInt(number1);
if(n == 1) Debug.Log(“positive”);
You’re going to run across situations where you need the actual value, so it would be better to get used to it.