Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 fuadshahmuradov · Mar 04, 2020 at 08:28 AM · 2d gamescene load

How can I change the character for the gameplay after selecting the character?

I have a 2D game in which my character goes left or right avoiding knives. I have 1 character set up with animations of walk and idle. I want a second character to be added, and the user to be able to choose to play with. My question is how can I change the character in the gameplay scene after the character selection which is done in another scene (before gameplay)? I have PlayerMove.cs which includes these codes to make walk animation.

 if(h > 0)
 {
         temp.x += speed * Time.deltaTime;
         sr.flipX = false;
         anim.SetBool("walk",true);    
  }
  else if (h < 0)
  {
         temp.x -= speed * Time.deltaTime;
         sr.flipX = true;
         anim.SetBool("walk",true);
  } 
  else if (h == 0)
  {
         anim.SetBool("walk",false);
  }

So I should also somehow use walk or walk1 in these codes to make them have animation when they move. I was planning to active an object(Player) which is selected. But as far as I am concerned, I can not access the gameplay scene during the selectPlayer Scene because it is not loaded yet.

alt text

alt text

selectplayer.png (279.8 kB)
gameplay.png (389.3 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Mar 04, 2020 at 08:49 AM

Hello.

First, you need to have the second character. It cna be a copy of the firstone. And at the start of the scene, disable the non selected one.

To know what the player selected in the last scene, you need to use the DontDestroyOnLoad property on some object (like a Game Manager) that will not be destroyed when changing scenes, so you can "save" the info.

I recommend you to watch the Persistance Data from official Unity tutorials.

Good luck!

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 Getsumi3 · Mar 04, 2020 at 08:57 AM

Hi.

The easiest way is to create two arrays (or List) with your charactes and save data to PlayerPrefs:

  • First list will contain all your characters on Selector scene.

  • Second list also will contain all your characters but on Gameplay screen and they're state must be set to SetActive(false).

On SelectPlayer scene when you select a character write selected characters ID to PlayerPrefs.

 public List<GameObject> characters = new List<GameObject>();
 public GameObject selectedCharacter;
 //Assign this method to the button that should select the character
 public void SelectCharacter(int ID)
 {
     selectedCharacter = characters[ID];
     PlayerPrefs.SetInt("CharID", ID);
 }

And on Gameplay scene when the scene is loaded get the data about saved character ID from PlayerPrefs, find this ID in your List and make the character with this ID visible SetActive(true). public List characters = new List(); public GameObject selectedCharacter;

 private void Start()
 {
     selectedCharacter = characters[PlayerPrefs.GetInt("CharID")];
     selectedCharacter.SetActive(true);
 }



P.S: Code not tested.

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

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

156 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Duplicate scene via script,Saving virtual World 2D 0 Answers

Game behaves differently when it restarts 1 Answer

Moving a 2d player and preventing them from passing through objects 1 Answer

Having 2D Character fall when in collision 0 Answers

respawn all after player die or doing checkpoint 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