Question by
FireHeart_GG · Jun 16, 2020 at 03:21 PM ·
c#cameramovement3dmouseposition
Issue with getting the mouse position in 3D and moving a gameobject on the y & z axis
, using System.Collections; using UnityEngine.EventSystems; using UnityEngine;
public class drag : MonoBehaviour
{
private void Update()
{
Vector2 mousePos = Input.mousePosition;
Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, transform.position.z));
print("WorldPos:" + worldPos);
print("mousePos:" + mousePos);
transform.position = new Vector3(transform.position.x, worldPos.y, worldPos.z);
}
}
I'm trying to get the mouse position and move an object to it, but it's getting the wrong position. Can someone help please? This is for a game jam :p
Comment