I was trying following things.
GameManager :
bool gameHasEnded = false;
public GameObject completeLevelUI;
public void CompleteLevel(){
completeLevelUI.SetActive(true);
}
public void EndGame(){
if(gameHasEnded == false){
gameHasEnded = true;
Invoke("Restart",2f);
}
}
void Restart(){
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
EndTrigger :
public GameManager gameManager;
void OnTriggerEnter(){
gameManager.CompleteLevel();
}
I get a log in the console "END". Earlier I was using Console.Log("END"); on CompleteLevel(), but I changed that source code. The old code seems to be working and not the new one. It's like Unity couldn't refresh that source code. (And I am sure that I have successfully saved the C# file.)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCollision : MonoBehaviour
{
public PlayerMovement movement;
void OnCollisionEnter(Collision collisionInfo)
{
Debug.Log(collisionInfo.collider.name);
if (collisionInfo.collider.tag == "obstacle")
{
movement.enabled = false;
FindObjectOfType<GameManager>().EndGame();
}
}
}
```


EndGame? Something in your UI? Is your GameManager getting destroyed on Scene reload or is something resettinggameHasEndedback to true? Are you sure theENDis not coming from a different script? Like the one that printsground\$\endgroup\$ENDlog then, it returned me toPlayerCollision. \$\endgroup\$OnTriggerEnter()is missing the parameter of the collisionOnTriggerEnter(Collider other). If is has not the parameter, Unity is not calling it on a collision since it can not magically know that it should use it for collision \$\endgroup\$