My solution was a bit different than the one presented in the lesson. The approach I took was like BindArraySize() but with the exception that I also Debug.Log the stringValue of the property. So there is no need to start the game. (This is how I undestood the challenge)
But i was expecting that it logs the string every frame. Like it was told in the lesson at around 5:00. Is the Editor script really part of OnGUI ? Seems like OnGUI is for GUI elements like buttons etc and not Editor scripts. Its a monobehaviour function.
What I noticed instead is that the log executes about 2-10 times when doing different actions in the unity editor while the raycaster script is visible in the inspector:
- moving the mouse to the inspector view
- moving it out of the inspector view
- arbitrary clicking (on press and release) in the inspector view
- editing a field.
Well, I do not quite understand when these scripts are actually executed and why they are executed different amount of times.
Here my solution if you like to test this:
void PrintString()
{
string currentString = serializedObject.FindProperty("StringToPrint").stringValue;
string print = EditorGUILayout.TextField("String to print", currentString);
if (currentString != print)
{
serializedObject.FindProperty("StringToPrint").stringValue = print;
}
Debug.Log(serializedObject.FindProperty("StringToPrint").stringValue);
}
You need to include UnityEngine at the top in order to use Debug.Log