Both my programming teacher and the student teacher were unable to solve this problem, so I’m turning to the forums. I’ve written a script where if I call the endgame function, it should also call the screen function from another script.
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public Text pointsText;
public GameOverScreen GameOverScreen;
int maxPlatform = 0;
void Start()
{
}
public void EndGame ()
{
print("GameOver");
GameOverScreen.Screen();
Debug.Log("GAME OVER");
}
void Restart ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
And I know that the endgame function is running, because the first print command successfully prints. However, for some reason it gets stuck on the call screen function, because it never happens, and the debug log command never prints. Here’s the script with the screen function:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameOverScreen : MonoBehaviour
{
public Text pointsText;
// Start is called before the first frame update
void Start()
{
print("GameOverStart");
}
public void Screen()
{
print("GameOver2");
scoreScript = GameObject.Find("Score").GetComponent<ScoreScript>();
gameObject.SetActive(true);
pointsText.text = scoreScript.scoreValue + " POINTS";
}
public void Restartbutton()
{
SceneManager.LoadScene("SampleScene");
}
public void Exitbutton()
{
SceneManager.LoadScene("MainMenu");
}
}
In fact, none of the functions of the GameOverScreen are actually working, since even print(“GameOverStart”) does not print.
All the inspector slots that should be filled are filled, and the funniest part about this is that these scripts used to work just fine, but then when I was cleaning up some lines of code that didn’t do anything, it stopped working, and then after I undid everything, it still wouldn’t work. Anyone know how to fix this?