Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pippo19 · Jan 06, 2014 at 08:30 PM · scenecommunicationdifferent

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nastasache · Jan 07, 2014 at 09:24 AM 0
Share

I think http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html it's the key.

avatar image pippo19 · Jan 07, 2014 at 02:45 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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):

  1. Create a new 'Controller' object in Scene 1.

  2. Attach the 'game controller' script to.

  3. Pass the character from selection script to the 'game controller' script

  4. 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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pippo19 · Jan 07, 2014 at 05:58 PM 0
Share

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

avatar image pippo19 · Jan 07, 2014 at 06:00 PM 0
Share

I have several characters, I can not put the script DontDestroyOnLoad () over all, otherwise how do you save only what I have selected?

avatar image pippo19 · Jan 07, 2014 at 06:08 PM 0
Share

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 ..

avatar image nastasache · Jan 07, 2014 at 09:28 PM 0
Share

DontDestroyOnLoad it's about the object where script containing it is attached. To understand the mecanism, play with attached $$anonymous$$iproject link text

undestructabletest.zip (6.4 kB)
avatar image pippo19 · Jan 10, 2014 at 05:45 PM 0
Share

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?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges