Let's create a method to update playerDeaths to see the method arguments that are being passed by reference in action.
Open up Utilities and add the following code:
public static class Utilities
{
public static int playerDeaths = 0;
// 1
public static string UpdateDeathCount(ref int countReference)
{
// 2
countReference += 1;
return "Next time you'll be at number " + countReference;
}
public static void RestartLevel()
{
SceneManager.LoadScene(0);
Time.timeScale = 1.0f;
// 3
Debug.Log("Player deaths: " + playerDeaths);
string message = UpdateDeathCount(ref playerDeaths);
Debug.Log("Player deaths: " + playerDeaths);
}
public static bool RestartLevel(int sceneIndex)
{
// ... No changes needed ...
}
}
Let's break down the code:
- First, it declares a new...