I somewhat knew that public variables can be changed by memory editor software, I wanted to be sure, so I made a little test using “Cheat engine”, by using this code.
public int a =101;
void Start(){
StartCoroutine(Count ());
}
void OnGUI(){
GUILayout.Button(""+a);
}
IEnumerator Count(){
for(;;){
yield return new WaitForSeconds(2f);
a ++;
}
}
Result: http://gyazo.com/0010223afdcfb943904f4190d8298e0b
Test Two, private and protected:
private int a = 5;
protected int b = 100;
void Start(){
StartCoroutine(Count());
}
void OnGUI(){
GUI.TextArea(new Rect(10,Screen.height/2,120,30),"Private int a: "+a);
GUI.TextArea(new Rect(10,Screen.height/2+40,120,30),"Protected int b: "+b);
}
IEnumerator Count(){
for(;;){
yield return new WaitForSeconds(2f);
a++;
b++;
}
}
Result: Screenshot - 0517f5b8f0d4f580552e54b8ac067916 - Gyazo
Private and protected types can be found and edited same as public.
Public variable can be easily found an changed to any integer.
So my question is:
Only way to keep variables safe is by only using private and protected access specifiers? If so, that means most variable accessing should rewritten, which is a pain.
Or are there other method for keeping run-time data safe, thanks!
Any experience and hints very appreciated.