- Home /
i need help with my script
im trying to make a multiplayer on the same keyboard for a 3d unity game. but i can't seem to get the script down without errors coming up. does anyone know how to have one player at the WASD keys and the arrow key? this is my script : using System.Collections; using System.Collections.Generic; using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public float moveSpeed;
// Use this for initialization
void Start ()
{
moveSpeed = 6.5f;
}
// Update is called once per frame
void Update ()
{
transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime);
}
}
Answer by s_awali · Dec 05, 2018 at 02:18 PM
By default the "Horizontal" and "Vertical" axis are mapped to both left-up-right-down arrows and WASD.
You might want to create a second set of axis (for instance "Horizontal2" and "Vertical2") with the same configuration as "Horizontal" and "Vertical" axis. Map the first set of axis with WASD only, and the second one to arrows only.
Finaly use Input.GetAxis("Horizontal")
and Input.GetAxis("Vertical")
for player 1, and Input.GetAxis("Horizontal2")
and Input.GetAxis("Vertical2")
for player 2.
For more info : https://docs.unity3d.com/Manual/class-InputManager.html
Your answer
Follow this Question
Related Questions
Best way to set up a city trading system script?,Best way to script city trading system? 1 Answer
creating and using list of prefabs 2 Answers
Can I change animation key frame property in script? 1 Answer
How to Write a Drag and Drop script for Unity 5.3.3? 4 Answers
how to make a detect rotation script for negative rotation too 2 Answers