To keep things simple, let's have the game manager adopt our new interface and implement its blueprint.
Update GameBehavior with the following code:
// 1
public class GameBehavior : MonoBehaviour, IManager
{
// 2
private string _state;
// 3
public string State
{
get { return _state; }
set { _state = value; }
}
// ... No other changes needed ...
// 4
void Start()
{
Initialize();
}
// 5
public void Initialize()
{
_state = "Manager initialized..";
Debug.Log(_state);
}
void OnGUI()
{
// ... No changes needed ...
}
}
Let's break down the code:
- First, it declares that GameBehavior adopts the IManager interface using a comma and its name, just like with subclassing.
- Then, it adds a private variable that we'll use to back the public State value we have to implement from IManager...