Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     static void OnUpdate()
     {
         bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
         if (doneBefore)
         {
             EditorApplication.update -= OnUpdate;
             return;
         }

         if (String.IsNullOrEmpty(EditorApplication.currentScene) && EditorBuildSettings.scenes.Length == 0)
         {
             #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
             if (EditorApplication.isUpdating) return;
             #endif

             LoadPunDemoHub();
             SetPunDemoBuildSettings();
             EditorPrefs.SetBool("PunDemosOpenedBefore", true);
             Debug.Log("No scene was open. Loaded PUN Demo Hub Scene and added demos to build settings. Ready to go! This auto-setup is now disabled in this Editor.");
         }
     }