- Home /
boolean issue
I have an issue with a boolean. It's showing up as true when supposed to be false any help? All the variables in the arrays are rigidbodies and are declared in the inspector. It's showing firstPhrase as true when its supposed to be false.
var a = [ab, ac, ad, ae, af, ag];
var b = [ba, bc, bd, be, bf, bg];
var c = [ca, cb, cd, ce, cf, cg];
var d = [da, db, dc, de, df, dg];
var e = [ea, eb, ec, ed, ef, eg];
var f = [fa, fb, fc, fd, fe, fg];
var allObjects = [a, b, c, d, e, f];
var theLetter = allObjects[Random.Range(0,allObjects.Length)];
var thePhrase = theLetter[Random.Range(0,theLetter.Length)];
var spawn = Instantiate(thePhrase, Vector3(-0.27, -0.55,0), Quaternion.identity);
if(spawn == ab || ba || ca || da || ea || fa){
firstPhrase = true;
}else if (spawn !== ab || ba || ca || da || ea || fa){
firstPhrase = false;
}
Answer by tanoshimi · Jan 31, 2015 at 08:47 AM
Aaargh, please type your variables - this code is just asking for errors!
I don't use UnityScript (for exactly this reason), but you said that "All the variables in the arrays are rigidbodies". And yet spawn
is an Object
(because that's what Instantiate returns). So your Boolean test will always return false.
Your answer
Follow this Question
Related Questions
Adding booleans to array and randomize 0 Answers
Boolean problem. 1 Answer
Ragdoll Rigidbody Array? 1 Answer
Array of custom class objects all return the same value? 1 Answer
String comparison, can't use false result as string. 4 Answers