- Home /
Two independant mouse cursors
Hi
I want to have two players, at the same time, each moving their own cursor (maybe one with a joystick, or the keyboard). Preferably with both having the functionality one finds on the mouse cursor in Unity.
How can I do this?
thanks.
Implement your own "fake" cursor. The operating system is not built to have more than one cursor, so you will have to "fake" it yourself.
Just google how to do it if you don't know ;)
Answer by perezbalen · Oct 16, 2013 at 05:24 AM
I figured as much, so I went ahead an did this (in case someone is interested):
public Texture customImageP2;
public float cursorSpeedP2 = 100.0f;
//Coordinates of Player´s 2 mouse. (starts center of screen)
private Vector3 mousePosP2 = new Vector3(Screen.width/2,Screen.height/2,0);
void OnGUI(){
//Player 2
//Move cursor
if (Input.GetKey(KeyCode.A)) //<--
mousePosP2 += new Vector3(-1 * cursorSpeedP2 * Time.deltaTime,0 ,0);
if (Input.GetKey(KeyCode.D)) //-->
mousePosP2 += new Vector3(1 * cursorSpeedP2 * Time.deltaTime, 0,0);
if (Input.GetKey(KeyCode.W)) //Up
mousePosP2 += new Vector3(0, 1 * cursorSpeedP2 * Time.deltaTime, 0);
if (Input.GetKey(KeyCode.S)) //Down
mousePosP2 += new Vector3(0, -1 * cursorSpeedP2 * Time.deltaTime, 0);
//Implement "clicking".
if (Input.GetKey(KeyCode.Q)) //RMC
{
//send fire 1 to under the mousePosP2
}
if (Input.GetKey(KeyCode.E)) //LMC
{
//send fire 2 to under the mousePosP2
}
//Draw the second Cursor
Rect posP2 = new Rect(mousePosP2.x, Screen.height - mousePosP2.y,
customImageP2.width,customImageP2.height);
GUI.Label(posP2,customImageP2);
}
So far I´ve yet to figure out how to implement the Player 2 right and left mouse clicks, so they behave as the real mouse clicks (or a way to fake/send a Input.GetMouseButtonUp(0) when the player presses "Q")
Your answer
Follow this Question
Related Questions
SideScrolling Mouse Pointer Aim - Help 0 Answers
Mouse pointer after scene change 0 Answers
Make a dotted line from an object to the mouse 2d 2 Answers
why input isn't working correctly? 1 Answer
MouseCursor > FlashPlayer 2 Answers