X
X
XAXAXAXAXAXAXAXAXAXAXAXAXA2019-11-11 07:30:18
C++ / C#
XAXAXAXAXAXAXAXAXAXAXAXAXA, 2019-11-11 07:30:18

How to properly organize interaction between scripts?

Hello comrades. The question is primarily for experienced people.
How to properly organize the interaction between scripts (links to each other).
That is, let's say I have a Player script. There is a main canvas MainUI. There is a game manager GameManager.
How should the player trigger an event (such as update score) in MainUI?
The only thing that comes to mind is Singletons. But this is a bad tone and I would like to do it on a pro. level.
As an option to do through dependencies, such as the player will have a MainUI field where a link to the class is placed.
BUT here comes the question. What about LOADED scenes? That is, I have a main scene, on it is a player, a canvas and a game manager.
I load the scene with the level separately. HOW DOES THIS SCENE with the level get through to the game manager? (I can’t put the link logically through the inspector in advance). Only through Singletons? Or do each time a component search by type.
HELP! I can't get up for a long time.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dollar, 2019-11-11
@dollar

Hello, friend!
I wanted to say that I did not like your nickname. Some kind of rush.
Everything else is top notch. Really, great question.
I subscribed to you.

M
mopsicus, 2019-11-12
@mopsicus

The issue of script connection is probably one of the most popular among novice developers. And here it's not about Unity, but about the development language. You need to tighten up C# a little and it will be easier.
In a specific example, you can really use a singleton, make it non-destructible via DontDestroyOnLoad, as Dance Macabre said.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question