Created
April 25, 2020 17:48
-
-
Save BiosElement/0f691aaaafc64f277e447adad8a1ded5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class RelativeMousePosition : MonoBehaviour | |
| { | |
| public float ActualMousePosition; | |
| public float RelativePosition; | |
| public float scaleFactor; | |
| // Start is called before the first frame update | |
| void Start() | |
| { | |
| scaleFactor = GetComponentInParent<Canvas>().scaleFactor; | |
| } | |
| // Update is called once per frame | |
| void Update() | |
| { | |
| ActualMousePosition = Input.mousePosition.x; | |
| RelativePosition = Input.mousePosition.x/scaleFactor; | |
| Debug.Log("Mouse Position: " + ActualMousePosition + " Relative: " + RelativePosition); | |
| } | |
| void OnRectTransformDimensionsChange() { | |
| scaleFactor = GetComponentInParent<Canvas>().scaleFactor; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment