I am making a platformer and when the player hits the water, it should die. I have this code here for death, I intend to put a death screen.
public class WaterDeath : MonoBehaviour
{
[SerializeField] private Transform player;
void OnTriggerEnter(Collider other) {
FindObjectOfType<GameManager>().DeathScreen();
}
}
This is basic the whole code on this script!
The script called GameManager have a function DeathScreen with Debug.Log(“You died”).
Here is the thing, when I load the game, I see this message on console, even if I am not even close to the collider. I put a code to load the scene on GameManager and it keeps looping forever.
There is a box collider with trigger on on an object called Water, which has the death script attached to it. It has rigibody.
My player has a capsule collider with character controller. I attached a rigibody to it with no physics enabled.
How I make this death message happens only when I touched the water and not when I start the game?
I wonder if I need to somehow to call this function on update(), although I dont see any code around doing this so I’m not sure on how to do it.
(Also I have this problem where the player sinks for half a second on the collider before the message is shown. if you know the solution to this too let me know!)
Thank you very much!