Hi there !
I resurrect this subject after a few years because I have trouble controlling the Unity Cursor with the Xbox controller left joystick. The context in game is this one :
- Oculus Player with movements controlled by left Xbox joystick
- Pressing B Button, a Pause Menu is displaying (simple canva Camera Space)
- Unity Cursor appear and shall “OnClick” buttons (among them : resume)
Of course, my question is about the third step of this process as I fail to recover joystick movement while canceling the one of the first step’s setup. The cursor in pause menu shall be controlled by left joystick.
I’m pretty new to c sharp and i’m confused between both coding and unity’s drag & droping logic on this specific task.
I will surely appreciate any help from you !
EDIT:
Now struggling on how to constraint GUI Cursor position at screen limits and how to make the GUI cursor act like a mouse, regarding “OnClick” behavior.
using System.Collections.Generic;
using UnityEngine;
public class XboxCursor : MonoBehaviour
{
public Vector3 originalPosition; //Original Position stored for "Start at Center position" Cursor behavior
private Vector3 startPos;
private Transform thisTransform;
public float sensitivity = 0.2f;
void Start()
{
thisTransform = transform;
this.transform.position = originalPosition; //Wrong method for reset to center position...
}
void Update()
{
// Joystick Axis Acting
Vector3 inputDirection = Vector3.zero * sensitivity;
inputDirection.x = Input.GetAxisRaw("Horizontal") * 0.1f;
inputDirection.y = Input.GetAxisRaw("Vertical") * 0.1f;
thisTransform.position = startPos + inputDirection * sensitivity;
startPos = thisTransform.position;
//Screen Constraint -- Not Working at all for some reason
this.transform.position = new Vector3(Mathf.Clamp(transform.position.x, -1f, 1f),
Mathf.Clamp(transform.position.y, -2f, 2f), transform.position.z);
// Mouse OnClick Mimetism
if (Input.GetButtonDown("Button A"))
{
Input.GetMouseButtonDown(0);
Debug.Log("Mouse Click !"); //But still at real mouse position ! xP
//TP Mouse (Bad Opt)
//Raycast GUI (Good Opt... Searching Doc...)
}
}
}
EDIT : Leaving this here, but subject abandoned after new UX project approach.
while it's not EXACTLY what you're looking for, I'm going through something similar, and have made some progress. (not complete, by any means, but maybe it'll help you) https://mcmap.net/q/26971/unity-trying-to-highlight-text-with-controller
– Virago