Answers for "unity get mouse position"

C#
22

unity get mouse position

Vector3 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Posted by: Guest on July-16-2020
11

how to find the mouse position unity

Vector2 mousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Posted by: Guest on March-12-2020
4

get mouse position javascript

<p>Click in the div element below to get the x (horizontal) and y (vertical) coordinates of the mouse pointer, when it is clicked.</p>

<div onclick="showCoords(event)"><p id="demo"></p></div>

<p><strong>Tip:</strong> Try to click different places in the div.</p>

<script>
function showCoords(event) {
  var cX = event.clientX;
  var sX = event.screenX;
  var cY = event.clientY;
  var sY = event.screenY;
  var coords1 = "client - X: " + cX + ", Y coords: " + cY;
  var coords2 = "screen - X: " + sX + ", Y coords: " + sY;
  document.getElementById("demo").innerHTML = coords1 + "<br>" + coords2;
}
</script>
Posted by: Guest on April-14-2020
0

How to get mouse position in unity

using UnityEngine;
using System.Collections;public class ExampleClass : MonoBehaviour
{
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Vector3 mousePos = Input.mousePosition;
            {
                Debug.Log(mousePos.x);
                Debug.Log(mousePos.y);
            }
        }
    }
}
Posted by: Guest on June-22-2021

C# Answers by Framework

Browse Popular Code Answers by Language