How do I allow my GameManager to register when my character collides with a collectable?
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).
Answer by ntavareswork1 · Mar 24, 2017 at 05:08 PM
//Grabbing the PlayerController Script
private PlayerController playerController
void Start(){
//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.
I also forgot to mention that all of this is in your game manager script
That actually worked great with some script changes. thanks.
Your answer
Follow this Question
Related Questions
A way to tell the player what they scored in the next scene 1 Answer
Saving highscore for multiple scenes 1 Answer
Help with 2D platformer (score),For my 2D game sometimes coins get added twice to the score?! 0 Answers
how to move score system through scenes with SceneManager.MoveGameObjectToScene 0 Answers
Changing Color 1 Answer