Hello! I have a game manager script and animal behavior script. I have my game winning conditions and effects set up on the game manager script to run once my score equals 3. The way to score is by pressing a button within a collision detection which sends the animal into the pen and I’d like to increment my score in the animal behavior script, but then access that score on the game manager script to tell the game if the player has won or not.
I’ve tried to reference the score from one script to the other, but it’s not even letting me type it out. Sorry if more information is needed, but let me know if any specifics and I’ll post more.
public void WinGame()
{
//This is the Winning Script, but need to set it to an actual win condition instead of pressing Q
if (score == 3)
{
if (!hasWon)
{
hasWon = true;
blueFireworks.Play();
greenFireworks.Play();
yellowFireworks.Play();
Cursor.lockState = CursorLockMode.None;
winScreen.gameObject.SetActive(true);
}
if (hasWon)
{
return;
}
}
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Barrier"))
{
transform.Rotate(Vector3.up, 180);
}
if (other.gameObject.CompareTag("Player"))
{
if (Input.GetKey(KeyCode.E))
{
caughtSound.Play();
GetCaught();
//Need to increment score here, store it, and access it on the game manager script to run the WinGame method
}
}
}
Again, WinGame() is in the GameManager script and OnCollisionEnter() is in the AnimalBehaviorScript. TLDR: How can I access a score that is incremented and saved in the AnimalBehaviorScript to determine if the game has been won and run my WinGame() on the GameManager script.
Thank you in advance and sorry if any confusion!