Unity doesn’t want us using SendMessage anymore, and for good reason, strings are bad! Here’s how I’m doing it now. It uses interfaces which unity recommends, and I’m sure we’ll get into in the future of this course.
ITriggerMessageTarget.cs
using UnityEngine.EventSystems;
public interface ITriggerMessageTarget : IEventSystemHandler
{
void OnPlayerDeath();
}
In PlayerController.cs, you have to change the class line to:
public class PlayerController : MonoBehaviour, ITriggerMessageTarget
Then you need to implement public void OnPlayerDeath()
public void OnPlayerDeath()
{
isControlEnabled = false;
print("Controls frozen");
}
Finally, call it in your CollisionHandler:
private void StartDeathSequence()
{
print("player dying");
ITriggerMessageTarget playerController = GetComponent<PlayerController>() as ITriggerMessageTarget;
playerController.OnPlayerDeath();
}
Hope this helps anyone else that ran into this problem.