O
O
okamilov2016-06-14 13:29:44
C++ / C#
okamilov, 2016-06-14 13:29:44

How to properly access a script in Unity that has a different name in each scene (GameController (1...10))?

Hello!
The situation is as follows: there are about 20 scripts, 19 of them are the same for
all scenes (character movement, joystick script, health output). I combined all
the main changes in lvl (location, type of enemies, number of enemies,
type of mission completion) into a GameController script, which I
was going to rewrite (or make an abstract class and inherit) for
each lvl.
This is where the problem arose, namely that many of the scripts
access the GameController (method call, variable access)
For a method, it looks like this:
GameController controller = GameObject.FindGameObjectWithTag (
"GameController). GetComponent ( "GameController") as GameController ;
// Create an object of the controller class
controller.KilledEnemy ();
For the variable:
if (GameController.enemyWin == enemyCreate)
And now the question itself: is it possible, for example, at lvl 3 to take, for example, a link for GameControllerLVL3
I myself thought to create some kind of variable in each of the scripts and simply
transfer the script or object in the unit editor , which has this
script, and somehow get access, but attempts were unsuccessful

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2016-06-14
@okamilov

Inherit them all from the same interface. GetComponent<>() (namely, the template one) works great with interfaces.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question