So basically, i am trying to receive score in my GameController, and no idea how to do this.
So for example lets say, if a person pushes a button in another script, the code would look something like this:
if (ConditionMet == True)
{
ScoreID = PUSHED_BUTTON_GRIP
return;
}
And then in game controller, you would get it like this:
if (ScoreID = PUSHED_BUTTON_GRIP)
{
Scorepoints = Scorepoints + 100
Scoretext.text = Scorepoints;
}
How would something like this be accomplished?
Keep in mind, it could be coming from a lot of scripts, and if it’s not possible, how would you do it?
I know this is possible in PHP, i would guess it’s possible in CSharp to, but I’m not sure.
you just need a reference to the gamecontroller in the “other” scripts, they can then either call a function/setter to set the value or more simply just expose the value as a public variable.
Assuming there is only one game controller in your project at a time you might find
handy.
If you don’t want to go down the direct reference route, look up “c# Events” or “unityevents”
LeftyRighty:
you just need a reference to the gamecontroller in the “other” scripts, they can then either call a function/setter to set the value or more simply just expose the value as a public variable.
Assuming there is only one game controller in your project at a time you might find
Unity - Scripting API: Object.FindObjectsOfType
handy.
If you don’t want to go down the direct reference route, look up “c# Events” or “unityevents”
I know i can do it that way, but there has to be a better way i would think, anyways I’m gonna dive into Unityevents then.