ACCESS MODIFIER
public
public access modifier is used when we want the variable or methods declared to be accessible from anywhere, whether it be inside or outside the class.
In the example above, isGameOver boolean variable has public access modifier. That is why, we were able to access the variable in MoveObjects Script as well.
private
private keyword makes the variable or method accessible only from inside the class.Â
In the same example shown, variable playerLife has private access modifier. That is why, we were able to access the variable only insider PlayerController Script. When we tried to access the variable playerLife from MoveObjects script, an error occured.