I am not an expert, but I will try to answer your question.
First: you can try to Serialize Field (where we usually serialize fields in Player.cs) and in Die() method call LoadGameOver() like this:
[SerializeField] GameObject level;
//..........................
private void Die()
{
level.GetComponent<Level>().LoadGameOver();
// .........................
}
I tried this on my own, it works correctly. I don’t know is it better or worse than the approach shown to us in Lection 113.
Second.
The Level.cs is a script.
What is the class exactly? As I read on Wikipedia:
a class is an abstract data type, it is a template for creating objects that provide initial values for states: initializing variable fields and implementing the behaviour of functions or methods. Other abstract data types - metaclasses, interfaces, structures, enumerations - are characterized by some of their own, other features.
So, when you ask “what kind of object is it” - I answer:
- Class is a data type
- Level is a class what has it’s own type: Level
Any class is a data type, and any class have its own name, therefore any class name is the type of this class.
So, your type of object is a type of class. It is “Level”.
For the Unity and C# compiler, I guess, it looks like this:
Script Name = Level (like in a solution explorer we have Level.cs)
Name of the Game Object on the Scene = Level
Class Name = Level
Class Name = Type Name => Type Name = Level
therefore the systems know what it has to look for. Do you feel the difference now? Script Name, Name of The Game Object on The Scene and Class Name (Type Name) it is like the different layers/blocks of one system. Unity, like operating system, see the difference between folder, .exe, .pdf, knows easily understands it.
If you create on your PC’s Desktop a folder with name Call Of Duty (for the all CoD games what you have on your PC), and if you have at the Desktop at the same time Call Of Duty.pdf (gaming guide, for example), Call of Duty.exe - it would not be a problem for the system to feel the difference between different types of objects with the same names.
And, the third part of this explanation. I tried to make it on my own and all works! Here the code with my commentary:
public class Player : MonoBehaviour
{
Level level; // it is the Level type of class which we will operate, because it has been declared in Level.cs
// and level variable of this type of class which we will use to store the cached reference
//...............
void Start()
{
SetUpMoveBoundaries();
level = FindObjectOfType<Level>(); // search for our Level class! not just for Level.cs or Level Game Object/Prefab
}
//.........
private void Die()
{
level.LoadGameOver(); // here we call LoadGameOver method
// .......................
}
}
P.S. I have half-written the fourth notebook on 96 sheets of extremely detailed synopsis, including all references to theory, documentation, etc.
Conceptually, the topic is really not simple. It’s good that you asked this question, for me it’s like an opportunity to practice and test my knowledge. Sorry for my bad english.