About 'Import & Refactor Code'!

cud_s04_import__refactor_code

#1

In this video (objectives)…

  1. Import our NumberWizard.cs code from previous section of the course.
  2. Assess what needs to be refactored / changed in order to have our code work with our user interface.
  3. Refactor the code including player input mechanism.

After watching (learning outcomes)… Refactor our code so that it is ready to hook up with our user interface.

(Unique Video Reference: 8_UI_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!


#3

The code in the video doesn’t look quite the same as that I ended up with after the earlier console version. For example, I had no “NextGuess” method. I’m not sure if this is me or a (minor) bug in the lecture…


#4
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizard : MonoBehaviour
{

    [SerializeField] int max;
    [SerializeField] int min;
    int guess;

    // Use this for initialization
    void Start()
    {
        StartGame();
    }

    void StartGame()
    {
        max = max + 1;
        guess = (max + min) / 2;
    }

    public void OnPressHigher()
    {
        min = guess;
        NextGuess();
    }

    public void OnPressLower()
    {
        max = guess;
        NextGuess();
    }
    void NextGuess() //This is the missing method he accidentally deletes in lecture 40//
    {
        guess = (max + min) / 2;
    }
}