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 Watercolours · Mar 21, 2013 at 12:59 PM · gameobjectcharactermenuselection

Selected object into next scene?

Alright. So I have two scenes:

  • Main Menu

  • Game

In the Main Menu I have a character select screen where I can pick the character I want to use. That part works just fine. I select the GameObject and an animation plays on the selected Object. When I've selected the character I want, I'll press "Play" which loads the Game scene.

But I just can't get that specific character to be shown in the next scene. I've already placed all the characters on top of each other, and want to destroy all the ones that was "not selected". I've tried making the SelectedCharacter GameObject Static, but with no luck. I just can't wrap my head around on how to make this work.

Any tips, ideas or whatever on what I should do? I'm completely stuck.

Comment
Add comment · Show 1
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 DeveloperGamesSK · Apr 15, 2019 at 08:45 PM 0
Share

Please add full script Thanks you :D

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Owen-Reynolds · Mar 21, 2013 at 02:11 PM

Can use a persistent "data" object to remember which char you want, then reference that in the next scene. For example (on an empty): class charStats { public int charNum; public int gold; ... }

Then in your menu script somewhere would have things like: GameObject.Find("CharData").GetComponent().charNum==2;

In your game scenes, each character could then check to see if it had the correct charNum: if(GO.Find("CharData")....charNum != myCharNum) Destroy(me)

The CharData gameObject with the script would be the only persistant (dontDestroyOnLoad.)

Alternative is to have the character be persistent. The (minor) problem there is you need to mark the starting spot for each scene and "teleport" the character there on scene load (since the new scene probably won't start at the exact xyz the last one ended.)

Comment
Add comment · 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
1

Answer by GuyTidhar · Mar 21, 2013 at 01:00 PM

Have you tried:

http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

If you do:

 DontDestroyOnLoad(rootGameObject);

Loading a new scene won't destroy the root game objects and all its child game objects and components.

Comment
Add comment · 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
0

Answer by Watercolours · Mar 21, 2013 at 08:29 PM

Alright, so I actually figured it out on my own. I somewhat did what Owen Reynolds said, but I used `PlayerPrefs` instead. Works like a charm and does exactly what I want. Can't believe I didn't know about it before. So much hassle for something so super simple.

Thanks for helping out guys!

Comment
Add comment · Show 5 · 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 mariaxx77 · Jan 14, 2014 at 08:16 PM 0
Share

Hey,

I know you posted this quite some time ago, is it possible you could share your solution? I'm doing something similar where I have a player selection menu, I then have my new scene where I want the selected character to appear based on the users choice from previous scene.

Thanks a lot.

avatar image Watercolours · Jan 16, 2014 at 07:31 AM 0
Share

You're right, this is quite old. And I don't understand why you had to ask that question when it's clearly answered here. Both in the post you've commented on and by Owen Reynolds. So please, just read..

avatar image mariaxx77 · Jan 16, 2014 at 11:07 AM 0
Share

You just said you used player prefs actually, I'm really new to unity so saying you used player prefs other than reading about it in documentation means nothing to me. You don't need to be so rude when this is meant to be a community forum where you help others. $$anonymous$$ bye

avatar image Watercolours · Jan 16, 2014 at 11:32 AM 0
Share

If reading the documentation doesn't mean anything to you, then you should probably get someone else to do the coding (or begin learning some other language with better APIs). But! since I'm in a good mood today I'll tell you the basics which are pretty obvious here.

In your CharacterSelector you want to assign all characters an Integer, get the one you pick from the menu and set it with PlayerPrefs like this:

PlayerPrefs.SetInt("CharacterInteger", chosenCharacterNumber);

and when you get a new scene you simply load it with:

PlayerPrefs.GetInt("CharacterInteger", chosenCharacterNumber);

then destroy the ones that weren't chosen. It's not the best method, but it works really well. I used it for a project in College and haven't used Unity since then so I'm a bit rusty, but this is pretty much all you need for a basic Character Selector with scene change.

avatar image mariaxx77 · Jan 16, 2014 at 01:21 PM 0
Share

Thanks a lot for your help. Sadly i cant get anyone else to code as I'm doing a project in school.. lol.

Will test this out now and see how it goes :)

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

14 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

Related Questions

Character selection system help script 2 Answers

sliding character selection menu 0 Answers

Any ideas to do a character selection 4 Answers

Char select / GUI button question. 3 Answers

Switching between multiple classes 2 Answers


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