- Home /
Some script in differents scene
hello to all, I'm making a game, especially the part where you choose the character you type. But I have a problem, how do I make two scripts communicate on two different scenes? I have 2 separate scenes, and a game where you choose a character, each with a script.
° scenes of selection
scripts of selection
. . . . . . . . . . . . . . . . .
°scenes of game
script of game
When I click on a character how do I bring up the option to 'another script so that players know which instantiated?
I think this is, but ... where should I put this code? on the script of the selection? how do I tell what the object does not destroy? thanks :D
Answer by nastasache · Jan 07, 2014 at 03:54 PM
Depending what is doing the object with selection script; you can keep it alive on all the scenes; but I think is better to use two scripts:
existing one for selection;
new one with DontDestroyOnLoad(), as a sort of 'game controller';
Supposing your sequence of loading scenes is: Scene 1 (character selection) -> Scene 2 (game scene):
Create a new 'Controller' object in Scene 1.
Attach the 'game controller' script to.
Pass the character from selection script to the 'game controller' script
Play the game, choose character, and load Scene 2.
You will see in the Scene 2 the 'Controller' object still exist; you can use it vars in scene scripts.
how i should made the third step? sorry but I'm Italian, so maybe I do not understand only because I have to translate and I lose a little sense :D
I have several characters, I can not put the script DontDestroyOnLoad () over all, otherwise how do you save only what I have selected?
if not, I have tried to do so but obviously it does not work: in the script of selection I created a GameObject variable and say that is equal to the chosen character, then in the same script I told him function Awake () { DontDestroyOnLoad (player.gameObject); }
.... but when I load the new scene I did not save ..
DontDestroyOnLoad it's about the object where script containing it is attached. To understand the mecanism, play with attached $$anonymous$$iproject link text
thank you! I understand how this works: D last two little questions ... the characterID how to use it? I can not use it?
syntax: gameCtrl.GetComponent (). characterID = 7; in javascript is it different?
Your answer
Follow this Question
Related Questions
Is there a way to script the scene to pause itself or debug. 1 Answer
Same Script in a different Scene with different conditions 1 Answer
Find Script from another script 2 Answers
Bridging iOS to Unity and load specific scene through Objective-C code. 1 Answer
Accessing non-static functions in an unattached, non-scene, "project" script 1 Answer