- Home /
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);
}
}
}
}
}
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.
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.
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;
}
}
No that's the script i'm using to move each sprite.
Do you have an idea for what i might need to do to make the swap actually work?
Your answer
Follow this Question
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