I am trying to complete roll a ball tutorial (https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial) in a different way by adding two balls. So two players can play the game. But the problem i am facing is that i want to configure the preferred keys for the second player like the firsl player uses the traditional arrow keys and the second player use w,a,s,d to move up left down right... my c-sharp code for the first player is this...
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); //Values for movement vector 3 takes three arguments like x y z for positions.
rb.AddForce (movement * speed);
}
}
Let me know if anyone have solution
Answered Similar question here.
The easiest solution that will require you not modify your key controls is to not use
Input.GetAxis
at-all. Detect each key press withInput.GetKey()
and theirkeycodes
enum. Problem solved! Now assign the two balls from the Editor. You can easily modify it to work with one ball if that's what you want.You can define more inputs in
edit -> project settings -> Input
. To add more inputs just increase the size value and config the new values in. At least input name and keys to the new inputs. Lastly, in your code call the new inputs for player 2 with the names you specified in the project settings.