I guess it doesn't affect the performance in any vizible level, but I will ask any way. I have this part of the script. (Keep in mind that it will be on many game objects at the same time) Only the Update part matters: On the first version, the system checks 2 statements every frame, but if I click the mouse button, nothing happens. Code (JavaScript): #pragma strict var selected : boolean; function OnMouseUp () { selected = true; } function Update () { if(Input.GetMouseButtonDown(0) && selected) { selected = false; } } On the second version, the system checks only 1 statement evry frame, but a command is run every time I click the mouse button. (Which happens a lot) Code (JavaScript): #pragma strict var selected : boolean; function OnMouseUp () { selected = true; } function Update () { if(Input.GetMouseButtonDown(0)) { selected = false; } } So my question is, which version is lighter for the computer? Even theoriticaly... Thanks!
If you only need to check input when selected is true then check selected first. If it's false then Input.GetMouseButtonDown(0) isn't even called even though it's in the same conditional. You'd also probably get better performance by checking that in one place and registering all selected GameObjects in a list.
So you are telling me that inside an if statement, if the first check is false, the system does not check the other one at all? for example: Code (CSharp): if(A && B) { //commands } if A = false, B is never checked
That being said - if you can check it in one place instead of a bunch of places then that's certainly the way to go.
Not only when using &&. It does what it needs to satisfy the condition. It's called short circuiting. In this example: Code (csharp): if(A || B) { //do something } If "A" is true it will never check B because A already satisfies the condition.