Let's see how a delegate type can be used as a method parameter:
- Update GameBehavior with the following code:
public class GameBehavior : MonoBehaviour, IManager
{
// ... No changes needed ...
void Start()
{
// ... No changes needed ...
}
public void Initialize()
{
_state = "Manager initialized..";
_state.FancyDebug();
debug(_state);
// 1
LogWithDelegate(debug);
}
public static void Print(string newText)
{
// ... No changes needed ...
}
// 2
public void LogWithDelegate(DebugDelegate del)
{
// 3
del("Delegating the debug task...");
}
void OnGUI()
{
// ... No changes needed ...
}
}
Let's break down the code:
- Calls LogWithDelegate() and passes in our debug variable as its type parameter
- Declares a new method that takes in a parameter of the...