Could anyone explain to me when to use == vs = ?
== is a comparison. It is a binary operator which returns a Boolean (true or false). Use it to compare two values to see if they are the same.
= is a mutator / assignment. It is a binary operator which returns an object AND assigns the value of the right hand expression into the left hand variable. Use it to assign a value to a variable.
e.g.,
var myNumber = 7;
if (myNumber == 7)
Debug.Log("It Works!");
1 Like
= means ‘make the object on the left the same as the object on the right’. This is called assignment.
== means ‘check if the object on the left is the same as the object on the right’. This is called comparison.
Thanks guys!