- Home /
Question by
Cuckboii69 · Jun 06, 2021 at 05:58 PM ·
c#canvasdistanceboxcolliderboxcollider2d
Get Distance From Mouse To Canvas BoxCollider
I am trying to get the distance from the mouse, to a box collider that is down the center of the canvas, however it only gets the distance from the center of the box collider rather than the entire collider itself
Vector3 mousePos = Input.mousePosition;
float distance = Vector3.Distance(screenCenter.transform.position, mousePos);
Debug.Log(distance);
cock.png
(121.6 kB)
Comment
Best Answer
Answer by Keyakit · Jun 06, 2021 at 06:22 PM
Vector3.Distance(Input.mousePosition, this.GetComponent<Collider>().ClosestPointOnBounds(Input.mousePosition));
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Character keeps jumping up walls 2 Answers
I cannot see button on camera preview 1 Answer
Create Unity UI Panel via Script 1 Answer