I realize this tutorial is 4 years old now, but I was hoping this issue could still be resolved. In creating the script to kill the player, I have encountered an error (in c#):
using UnityEngine; using System.Collections; public class Player : MonoBehaviour { public class PlayerStats { public int Health = 100; } public PlayerStats playerStats = new PlayerStats(); public void DamagePlayer (int damage) { playerStats.Health -= damage; if (playerStats.Health <= 0) { GameMaster.KillPlayer(this); //"GameMaster.KillPlayer" is where the error appears } } }
Severity Code Description Project File Line Suppression State
Error CS0120 An object reference is required for the non-static field, method, or property ‘GameMaster.KillPlayer(Player)’ 2D Platformer.CSharp C:\Users\Public\Documents\Unity\2D Platformer\Assets\Player.cs 19 Active
Any help in fixing this would be greatly appreciated, as I’m rather lost myself. I could not find a similar issue, sorry if this question has been asked already.