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 Kensharma · Mar 07, 2014 at 02:15 AM · 2dcharactersystemswitch

2D Character Switch Systsem (Same Location)

Hello developers;

Looking for some insight as to how some of you have implemented a character switch into your game. I have 3 characters that I need to always remain at the same position as eachother, and have the ability for a player to switch between any of the 3 by pressing a button on the gui. There would of course be three buttons and when one character becomes visible, the other 2 are not.

Keep in mind that this is in a 2d environment, meaning that a camera workaround won't cut it.

Thanks for any help.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Destran · Mar 07, 2014 at 04:08 AM

Make all three character sprites a child to a single empty gameobject so that their positions and what not all remain the same. Then enable/disable their renderers.

So I'm pretty new to scripting but I'll try an example.

 #pragma strict
 
 var character1 : Renderer; // Your first character
 var character2 : Renderer; // Your second character
 var character3 : Renderer; // your third character
 
 var activechar = 0; // when 0 active character is char1, when 1 active character is char2, etc.
 
 function Start()
 {
 activechar = 0;
 character1.enabled = true;
 character2.enabled = false;
 character3.enabled = false;
 }
 function Update()
 {
 if(Input.GetKeyDown(KeyCode.E))//if they press E the active char is switched
 {
 activechar++;
   if(activechar >2)
    activechar = 0;  // makes sure it cycles through your 3 characters
 }
 
 IsActive(); //calls the IsActive function to see which sprite is enabled
 
 }
 
 function IsActive()
 {
 if(activechar==0) //shows only char 1
 {
 character1.enabled = true;  
 character2.enabled = false;
 character3.enabled = false;
 }
 if(activechar == 1) //shows only char 2
 {
 character1.enabled = false;  
 character2.enabled = true;
 character3.enabled = false;
 }
 if(activechar == 2) //shows only char 3
 {
 character1.enabled = false;  
 character2.enabled = false;
 character3.enabled = true;
 }
 }


Drag your 3 sprites onto the renderer areas in your empty gameobject in the inspector thing to match the char1/char2/char3. There might be a better way to do this, but I'm pretty new to Unity so I'm still learning. Hope this works!

Comment
Add comment · Show 2 · 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 Destran · Mar 07, 2014 at 04:09 AM 0
Share

Oh and attach this script to the gameobject aswell :D

avatar image Kensharma · Mar 08, 2014 at 06:16 AM 0
Share

Thanks for the help. I will try to work with this and modify it to suit my needs.

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

21 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

Related Questions

switch player and npc follow player 0 Answers

2D example: Flip character without moving 0 Answers

Unity 2D Top Down Jump 1 Answer

2D Character Flip 2 Answers

changing player (getting in vehicles) 3 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