Quantcast
Channel: Answers for "The if does not work?"
Viewing all articles
Browse latest Browse all 4

Answer by tanoshimi

$
0
0
I have no idea what you're intending to achieve, but I imagine the reason why your code is not doing what you think it should is because the scope, types and values of your variables are all over the place! To start off, you have a global variable "jam", which is explicitly declared as a String with the value "jam": var jam : String = "jam"; You then have another global variable "jam2", which is implicitly declared as an empty string: var jam2 = ""; Note that, in the check() function, it is these two values that are being compared. They're not the same, so the Debug.Log is correctly no printing anything. In the Awake() function you're then declaring a local variable, also named "jam2", and giving it an *integer* value: var jam2 = Random.Range(0, 100); And then in the OnGUI() function you're setting the global variable "jam" (which, you recall, was initialised as a string "jam") to be the edited value returned by the textfield: jam = GUI.TextField (Rect (Screen.width / 2 + 50, 260, 100, 30), jam); See the problem? Give your variables more descriptive names and think about the scope in which they're used and problems like this are resolved pretty easily.

Viewing all articles
Browse latest Browse all 4

Trending Articles



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