I am recreating an NES platformer. I have a game manager set up to run the game flow and its linked to a canvas manager script to do things like allowing buttons to transition between scenes and display the players current health and score.
What I need help with is either linking a score variable stored in my character’s c# script to the _score variable in my GameManager script OR allow my GameManager to update my score variable itself by tracking when a collectable is picked up (as it is already using DoNotDestroy).
//Grabbing the PlayerController Script
private PlayerController playerController
//Identifying what the playercontroller is
playerController = FindObjectOfType<PlayerController>();
//If the score variable on your player controller is public then you can
//Use playerController.The score variable you made in the script
You have to start by making a reference to your player script. In this instance I put PlayerController. After you make a referance to the playercontroller you have to also say what PlayerController is. Since you only have 1 player script you can use FindObjectOfType. If you were to have any more unity would come back with an error. After you do both of those things you can finally put the player score in by referencing your player script and then a dot with your score variable after that.