- Home /
[SOLVED] How to still move the character but with different keys?
Hey guys, How to add two player with on one keyboard? I basically have two object with 2 movement scripts and I add Player1Horizontal with A&D keys and Player2Horizontal with right and left arrows, but I doesn't work. [Updated]Player 1 Script publice GameObject Player; public float speed; Rigidbody2D rb;
void Start()
{
rb = Player.GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
Player1();
}
void Player1()
{
float x = Input.GetAxis("Player1Horizontal");
rb.velocity = new Vector3(x * speed, rb.velocity.y, 0);
}
}
Do the same for Player2
On both players object I have a rigidbody and collider
Here's is some photos alt text
Hey Guys, I solved the problem. The problem is to that I need to add an gameobject and reference it in my script. cause the script got confuse to which rigidbody to use,
I just thought I won't delete it because someone might find this useful. If you want to delete it, than go a head
Your answer
Follow this Question
Related Questions
How to move the object to where the object is already pointing to? 1 Answer
(URGENT) I have a swinging axe I can get to rotate once in 1 direction but i need it to loop 3 Answers
[C#] Quaternion Rotations with Input.GetAxis problems. 1 Answer
How do I make a crouch script unity 3d 1 Answer
Why when using get; set; in one script i'm getting null in other script that use it ? 1 Answer