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:

  void OnGUI() {
   if (this.gameScript.gameView == "options") {
    this.gameScript.mainCamera.transform.eulerAngles = new Vector3 (120, 23, 0);

    GUI.skin = this.gameScript.currentGUISkin;

    //check to see if any options changed
    if (previous_use_0 != use_0) {
     this.setOption ("use_0", this.use_0);
     GameControllerScript.performRestart = true;
    }

    if (this.previous_board_type != this.board_type) {
     this.setOption ("board_type", this.board_type);
     GameControllerScript.performRestart = true;
    }

    if (previous_play_sounds != play_sounds) {
     this.setOption ("play_sounds", this.play_sounds);
    }

    if (this.previous_timer_duration != this.timer_duration) {
     this.setOption ("timer_duration", this.timer_duration);
     GameControllerScript.performRestart = true;
    }



    //set the label
    GUILayout.Label ("Options", "BigLabel");

    scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width), GUILayout.Height(Mathf.Ceil(Screen.height * .80f)));



    //Sounds
    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (this.play_sounds, "Play Sounds", currentGUISkin.toggle)) {
     this.play_sounds = true;
    }
    else {
     this.play_sounds = false;
    }
    GUILayout.Label ( "Play Sounds", "ToggleLabel");
    GUILayout.EndHorizontal();


    GUILayout.Label ("WARNING! Changing any of the following options will cause the game to reset!", "ToggleLabelWarning");

    GUILayout.Label ("Game Board Type", "Subheader");
    //Game Board Type
    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (this.board_type == "Solid Cube", "Solid Cube", currentGUISkin.toggle)) {
     this.board_type = "Solid Cube";
    }
    GUILayout.Label ( "Solid Cube (27 Blocks)", "ToggleLabel");
    GUILayout.EndHorizontal();


    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (this.board_type == "Hollow Cube", "Hollow Cube", currentGUISkin.toggle)) {
     this.board_type = "Hollow Cube";
    }
    GUILayout.Label ( "Hollow Cube (26 Blocks)", "ToggleLabel");
    GUILayout.EndHorizontal();


    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (this.board_type == "Four Walls", "Four Walls", currentGUISkin.toggle)) {
     this.board_type = "Four Walls";
    }
    GUILayout.Label ( "Four Walls (24 Blocks)", "ToggleLabel");
    GUILayout.EndHorizontal();


    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (this.board_type == "Box Outline", "Box Outline", currentGUISkin.toggle)) {
     this.board_type = "Box Outline";
    }
    GUILayout.Label ( "Cube Outline (20 Blocks)", "ToggleLabel");
    GUILayout.EndHorizontal();



    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (this.board_type == "No Corners", "No Corners", currentGUISkin.toggle)) {
     this.board_type = "No Corners";
    }
    GUILayout.Label ( "No Corners (19 Blocks)", "ToggleLabel");
    GUILayout.EndHorizontal();


    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (this.board_type == "No Corners/Center", "No Corners/Center", currentGUISkin.toggle)) {
     this.board_type = "No Corners/Center";
    }
    GUILayout.Label ( "No Corners/Center (18 Blocks)", "ToggleLabel");
    GUILayout.EndHorizontal();


    //TIMER OPTIONS ####################################################
    GUILayout.Label ("Timer", "Subheader");

    foreach (int i in this.GetTimerDurationTimes())
    {
     GUILayout.BeginHorizontal ();
     if (GUILayout.Toggle (this.timer_duration == i, "", currentGUISkin.toggle)) {
      this.timer_duration = i;
     }
     GUILayout.Label (TimerDurationToString (i), "ToggleLabel");
     GUILayout.EndHorizontal();
    }




    //Other OPTIONS ####################################################
    GUILayout.Label ("Block Numbers", "Subheader");

    //Use Zeros
    GUILayout.BeginHorizontal ();
    if (GUILayout.Toggle (use_0, "Use 0s (Note: Changing this will reset the current game!)", currentGUISkin.toggle)) {
     use_0 = true;
    }
    else {
     use_0 = false;
    }
    GUILayout.Label ( "Use Zeros", "ToggleLabel");
    GUILayout.EndHorizontal();



    foreach (Touch touch in Input.touches) {
     if (touch.phase == TouchPhase.Moved)
     {
      // dragging
      scrollPosition.y += touch.deltaPosition.y;
     }
    }

    GUILayout.EndScrollView();

    if (GUILayout.Button ("Return to Menu", "Button")) {
     gameScript.gameView = "menu";
    }
   }
  }