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 ZacharyHarmon · Dec 25, 2018 at 07:29 PM · 2dmultiplayerunity 2dco-op

Drop In Drop Out System with Input?

I'm trying to code a drop in drop out system with input. Basically i have 2 sprites and im trying to swap between controlling each one. Right now I have a button i press on the keyboard and it switches which sprite is active however it does not let me show the animations for the other sprite and i can't control it. It also makes the other sprite that i'm not swapped to go off screen. I need both sprites to stay on screen and be able to press a button and and be able to control the other with the same input. If anyone could help me it would be much appreciated i couldn't find anything about it on google considering this is a very specific problem. Here's my code for the keyboard button swap function.

public class PlayerSwap : MonoBehaviour {

 GameObject YitoSprite, AisaSprite;
 int characterselect;
 public bool IsStillActiving;


 // Use this for initialization
 void Start () {
     characterselect = 1;
     YitoSprite = GameObject.Find("YitoSprite");
     AisaSprite = GameObject.Find("AisaSprite");

 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetButtonDown("Change"))
     {
         if (characterselect == 1)
         {
             characterselect = 2;
         }
         else if (characterselect == 2)
         {
             characterselect = 1;
         }
         if (characterselect == 1)
         {
             AisaSprite.SetActive(true);
             YitoSprite.SetActive(false);
         }
         else if (characterselect == 2)
         {
             AisaSprite.SetActive(false);
             YitoSprite.SetActive(true);
         }
      
         }
     }
 }

}

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 Vega4Life · Dec 25, 2018 at 08:59 PM 0
Share

We need to see the code that is manipulating your sprites. This particular bits of code (although not super clean), isn't doing enough to solve a problem or give you hints on how to address it.

avatar image ZacharyHarmon · Dec 25, 2018 at 09:23 PM 0
Share

Basically whenever i start the game it's using the same movement script for each sprite but i only want to be able to control 1 sprite at a time and be able to swap between which sprite im controlling through input.

1 Reply

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

Answer by ZacharyHarmon · Dec 25, 2018 at 09:21 PM

This is the code i'm using right now for movement. But i don't know if it should be or should not be working. It moves at least one of the sprites based off where they are on the x or y axis. It works for one but i'm trying to swap the controls and switch to the other sprites. So use the same set of controls but just change which sprite i'm controlling with the push of a button.

public class CharacterMovementScript : MonoBehaviour {

 public Animator animator;

 // Update is called once per frame
 void Update()
 {
     Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0.0f);

     animator.SetFloat("Horizontal", movement.x);
     animator.SetFloat("Vertical", movement.y);
     animator.SetFloat("Magnitude", movement.magnitude);


     transform.position = transform.position + movement * Time.deltaTime;
 }

}

Comment
Add comment · Show 3 · 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 Vega4Life · Dec 25, 2018 at 09:48 PM 0
Share

Is this an answer?

avatar image ZacharyHarmon Vega4Life · Dec 25, 2018 at 09:50 PM 0
Share

No that's the script i'm using to move each sprite.

avatar image ZacharyHarmon Vega4Life · Dec 27, 2018 at 01:40 AM 0
Share

Do you have an idea for what i might need to do to make the swap actually work?

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

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

Need Help Push and pull script for co-op/multiplayer 0 Answers

Help with a 2d camera Controller 1 Answer

How to get GUI text to appear on screen in 2d? 1 Answer

Network just for 2 player 0 Answers

Changing Size of Tilemap 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