- Home /
Moving an in-game cursor using the player's current mouse position?
Okay so basically in our game the main menu for the game is displayed on an in-game laptop which has it's own mouse cursor exclusive to the laptop screen. When the player moves their real mouse it navigates this in-game cursor across the virtual laptop screen, relative to the player's mouse position. This is what I have so far:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TestGUICursor : MonoBehaviour {
public float fcursorspeed;
public GameObject Cursor;
Vector3 cursorPosition;
void Update ()
{
cursorPosition = new Vector3(Input.GetAxis("Mouse X") * fcursorspeed, Input.GetAxis("Mouse Y") * fcursorspeed, 0f);
Cursor.GetComponent<RectTransform>().localPosition = cursorPosition;
}
}
This is the current behavior: https://gfycat.com/HotMelodicElephant
Bandicam sucks and removed my mouse cursor, but basically when I move my mouse around the in-game cursor jitters around; and when my mouse is at rest the in-game cursor resets to it's original position. The project's main programmer suggests using the mouse position value from the Event System, but neither of us has an idea on how to access that value.
Your answer
Follow this Question
Related Questions
UI and mousePosition not centered the same way ? 1 Answer
pop up a canvas when the time is up 1 Answer
[c#] first script isnt disabling canvas and player cant move (issue with first script) 0 Answers
Animating GameObject into UI Element 1 Answer
Unity crashes when using ExecuteAlways on a UIBehaviour 0 Answers