Input.mousePosition doesnt work
I want to drag an image of a canvas, i'm using the onDrag function to set the position of the image to the position of my mouse but when i run the application, and i try to drag the image, the image dissapear, but i realized that the image doesn't dissapear, but the position of the image is not the same as the mouse, when my mpuse gets the values, for example: (204, 15, 0) the image gets values like: (4676, 2345, 0) and i dont know why. Please help, this is my code.
using UnityEngine; using System.Collections; using UnityEngine.EventSystems;
public class NewBehaviourScript : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
 public static GameObject item;
 Vector3 startPosition;
 public void OnBeginDrag(PointerEventData eventData)
 {
     item = gameObject;
     startPosition = transform.position;
     Debug.Log(Input.mousePosition);
 }
 public void OnDrag(PointerEventData eventData)
 {
     transform.position = Input.mousePosition;
     Debug.Log(Input.mousePosition);
 }
 public void OnEndDrag(PointerEventData eventData)
 {
     item = null;
     transform.position = startPosition;
     Debug.Log(Input.mousePosition);
 }
}
What kind of canvas are you using? I didn't have this problem with the Screen space - overlay type.
Your answer
 
 
             Follow this Question
Related Questions
How to set canvas image to a Texture2D created in a script at runtime? 1 Answer
Trying to drag GameObject using touch input 0 Answers
Scaling an image sent to UI Image 0 Answers
Playing a Video on raw image 0 Answers
Unity UI does not visible when i drag using canvas set to screen space - camera 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                