Let's create a simple delegate type to define a method that takes in a string and eventually prints it out using an assigned method:
- Open up GameBehavior and add in the following code:
public class GameBehavior : MonoBehaviour, IManager
{
// ... No other changes needed ...
// 1
public delegate void DebugDelegate(string newText);
// 2
public DebugDelegate debug = Print;
// ... No other changes needed ...
void Start()
{
// ... No changes needed ...
}
public void Initialize()
{
_state = "Manager initialized..";
_state.FancyDebug();
// 3
debug(_state);
}
// 4
public static void Print(string newText)
{
Debug.Log(newText);
}
void OnGUI()
{
// ... No changes needed ...
}
}
Let's break down the code:
- Declares a public delegate type named DebugDelegate to hold a method that...