So, I was looking at an Inline if-statement that uses Ternary Operators. This is basically my current code, which I want to make more compact.
private void Move(Vector3 direction) {
if(direction != Vector3.back && direction != Vector3.forward)
transform.Rotate(0,(direction == Vector3.right ? 90 : -90),0);
else
transform.Rotate(0,(direction == Vector3.back ? 180 : 0),0);
transform.Translate(Vector3.forward, Space.Self);
}
I really want something compacted like this:
private void Move(Vector3 direction) {
transform.Rotate(0,(direction == Vector3.right ? 90 : -90 || direction == Vector3.back ? 180 : 0),0);
transform.Translate(Vector3.forward, Space.Self);
}
Is there anyway to do this? Just take this example. I want to know how to compile several built-in if statements, so I don’t need to have more lines of code for no reason if I can avoid it.
Thanks for taking the time to read my question.
source
share