Hi, i have some logic operators in an if statement, i was wondering how can you access or call back the outcome of that operation, rather than writing another if statement for an example what im doing is this:
objects are a,b,c and i have an if statement set up like this:
if (a && b || a && c || b && c) {
some actions
}
what i need to figure out is which of the operations above returned the true value, and assign a specific action rather than the same action, if any were to pass as true, to save some coding and processing power, for performance issues and optimization.
This will allways only call one command (because the code will skip other parts on succes because of the else statement). If you want to execute commands for all of your conditions that return true, just skip the else command.
I guess the actual condition is more complex than (a && b). The result of a logic “and” / “or” is a boolean, so you can store the result it in a variable if you want to use the value multiple times:
// C# or UnityScript
var ab = a && b;
var ac = a && c;
var bc = b && c;
if (ab || ac || bc)
{
//some general actions
if (ab)
{
// additonal conditional actions for ab
}
else if (ac)
{
// additonal conditional actions for ac
}
else if (bc)
{
// additonal conditional actions for bc
}
}
If you need “some general actions” you could also use Lovrenc solution and put the general code in a function which you can call from each case.