- Home /
Public functions not calling and scripts not being set to active
I'm trying to call a public function and set a script to active however neither the script nor the function work when called.`public class CinemaScript : MonoBehaviour { public GameObject[] popcorn; //public GameObject gameCamera; public float spawnInterval = 0.1f; public float gameTimeEnd = 20.0f;
public float timer = 0;
public float gameTime = 0;
private GameObject bucket;
private leaderBoardScript LBS;
private achievementScript ACS;
[SerializeField] private GameObject tutorialObject;
[SerializeField] private GameObject winScreen;
[SerializeField] private GameObject loseScreen;
private bool firstGame = false;
// Start is called before the first frame update
void Start()
{
bucket = GameObject.Find("Bucket");
LBS = GetComponent<leaderBoardScript>();
ACS = GetComponent<achievementScript>();
// Checking if this is the first game in order to show or not gallery notification if player wins.
if (PlayerPrefs.GetInt("cinneAch") == 0)
firstGame = true;
else
firstGame = false;
}
// Update is called once per frame
void Update()
{
if (GetComponent<achievementScript>() == null || GetComponent<leaderBoardScript>() == null)
{
Debug.Log("big BOi erreror");
}
if (!tutorialObject.activeSelf && !winScreen.activeSelf)
{
if (gameTime < gameTimeEnd)
{
gameTime += Time.deltaTime;
if (bucket.GetComponent<BucketScript>().score < bucket.GetComponent<BucketScript>().scoreLimit)
{
timer += Time.deltaTime;
if (timer >= spawnInterval)
{
Vector2 point = Random.insideUnitCircle.normalized * 10;
int popcornPrefab = Random.Range(1, popcorn.Length);
Instantiate(popcorn[popcornPrefab - 1], new Vector3(point.x, transform.position.y, point.y), Quaternion.identity);
timer = 0;
}
}
else
{
// The player won. Turning gallery notification on.
if (firstGame)
GameObject.Find("GalleryNotificationHandler").GetComponent<GalleryNotification>().galleryNotification = true;
LBS.cinneworldEnd((int)gameTime);
ACS.enabled = true;
winScreen.SetActive(true);
}
}
Is it correct that the player should win if there is time left and score limit has not been reached? If you are not getting any errors I think the most probable cause is that you never get to the part with
LBS.cinneworldEnd((int)gameTime);
ACS.enabled = true;
that i assume you are trying to reach.
Try write a Debug.Log("code reached"); before LBS.cinneworldEnd((int)gameTime);
ACS.enabled = true; and see if you actually reach that part.
WinScreen sets active though which is the weird part about this bug
So set a breakpoint at LBS.cinneworldEnd((int)gameTime); and see if the debuger gets there, then you can try step into the function and see what happens. This should give you the answers to what is happening. :)