How to move mouse cursor with joystick?
HI,
It seems like this question has already been discussed many times. But I couldn't find the solution for my case. All the discussions are either about camera rotation according to mouse movement or object control via mouse. But I need to control the mouse pointer with joystick (or keyboard). It looks like a really simple question, but I'm confused. Currently, I'm trying to hide hardware cursor and recreat my own, controlling it with Input.GetAxis("Horizontal")
or Input.GetAxis("Mouse X")
but the cursor just disappears and Event System reports no movement. However, if I use Input.mousePosition.x
my custom cursor is well created and controlled with mouse. Unfortunately, I need to control it only with Joystick. In addition, it doesn't work with Project Settings>>Input (or maybe I'm change something wrong there) Thanks in advance.
public class cursor : MonoBehaviour
{
public Texture2D cursorImage;
private int cursorWidth = 32;
private int cursorHeight = 32;
public float horizontalSpeed = 2.0F;
public float verticalSpeed = 2.0F;
void Start()
{
Cursor.visible = false;
}
void OnGUI()
{
float h = horizontalSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;
float v = verticalSpeed * Input.GetAxis("Vertical") * Time.deltaTime;
GUI.DrawTexture(new Rect(h, Screen.height - v, cursorWidth, cursorHeight), cursorImage);
if (Input.GetButtonDown("Fire1"))
{
Input.GetMouseButtonDown(0);
Debug.Log("Mouse Click !");
}
}
}
Answer by dragon_script · Mar 30, 2020 at 04:21 PM
I have the same question. I need to move the cursor with the controller.
Your answer
Follow this Question
Related Questions
Issue with mouse input when locking the cursor 2 Answers
How to control global mouse 0 Answers
How to check if a player click on a object: Android Mobile 1 Answer
Input.AnyKey for gamepads? 0 Answers