Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by willwdaniels87 · Mar 20 at 01:00 AM · 2d game2d-platformer2d animation2d-gameplay2d array

Switch Players during play

I'm making a 2d platformer game and I want to be able to swap characters during play with the click of a button. All my characters are animated (Walk, run, jump etc.) and will have different attack moves and attributes. My main player holds a UI/game manager so I would also need this to travel between scenes with players. I'm guessing I need to make an array and deactivate each player etc but I haven't been able to figure this one out, Any help or advice would be much appreciated. I'm pretty new to this

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 SolPurposeGames · Mar 20 at 06:19 PM 0
Share

If its 2d then you can use SpriteRendere.sprite = newsprite.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by willwdaniels87 · Mar 21 at 06:13 AM

Got it working sort of with the following script but my animations of the two different players clash.

public class PlayerSwitch : MonoBehaviour { public GameObject play1, play2; private int characterSelect;

 void Start()
 {
     characterSelect = 1;
     play1 = GameObject.Find("Buck");
     play2 = GameObject.Find("Bill");

 }


 void Update()
 {
     if (Input.GetButtonDown("Fire3"))
     {
         if (characterSelect == 1)
         {
             characterSelect = 2;
         }
         else if (characterSelect == 2)
         {
             characterSelect = 1;
         }


     }

     if (characterSelect == 1)
     {
         play1.SetActive(true);
         play2.SetActive(false);
         play2.transform.position = play1.transform.position;
         play2.transform.rotation = play1.transform.rotation;
     }
     else if (characterSelect == 2)
     {
         play1.SetActive(false);
         play2.SetActive(true);
         play1.transform.position = play2.transform.position;
         play1.transform.rotation = play2.transform.rotation;
     }

 }

}

Any help with the animation controller issue? My UI and scene loading is also playing up but I think I'll be able to solve that issue.

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 pr_0_0_ · Mar 21 at 07:35 AM

Why are you making the character which is to disappear move and rotate? Shouldn't it be the other way round? Also I'm not sure about this, but probably it will be better if you put the SetActive (false) in the end, so that the transformation happens before the character disappears. Try this:

      if (characterSelect == 1)
      {
          play1.SetActive(true);
          play1.transform.position = play2.transform.position;
          play1.transform.rotation = play2.transform.rotation;
          play2.SetActive(false);
      }
      else if (characterSelect == 2)
      {
          play2.SetActive(true);
          play2.transform.position = play1.transform.position;
          play2.transform.rotation = play1.transform.rotation;
          play1.SetActive(false);
      }
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

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

,Spawning snow or changing tilesets to snow as the player walks past them 0 Answers

Left/Right movement 2D game,Why is this code to make my character move left/right not working? 0 Answers

so I'm trying to make a 2D platform but the first animation i make is the only one that registers 0 Answers

Having some stuck issues on the 2D infinite runner 0 Answers

[2d Game]How to attach gameObject with HingeJoints 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