- Home /
 
ScreenPointToLocalPointInRectangle not giving output
I started to make a script for touch control behavior to a UI panel. In the screen there is a UI Panel with an image component. So if I click on UI panel, the "hit" message must be shown on the console. But it doesn,t. The script is as follows.
 using System.Collections;
 using UnityEngine.EventSystems;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class TouchControls : MonoBehaviour,IDragHandler,IPointerUpHandler,IPointerDownHandler {
     private Image Touchpanel;
     Vector3 inputVector;
 
     // Use this for initialization
     void Start () {
         Touchpanel = GetComponent<Image>();
     }
     
 
     public virtual void OnPointerDown(PointerEventData ped){
         OnDrag(ped);
     }
 
     public virtual void OnDrag(PointerEventData ped){
         Vector2 pos;
         if (RectTransformUtility.ScreenPointToLocalPointInRectangle(Touchpanel.rectTransform, ped.position, ped.pressEventCamera, out pos))
         {
             Debug.Log("hit");
         }
     }
 
     public virtual void OnPointerUp(PointerEventData ped){
        
     }
 }
 
               What have I done wrong in the code to not get the "hit" message? Any help is valued highly.
Answer by qobion · Apr 17, 2019 at 11:02 PM
For a RectTransform in a Canvas set to Screen Space - Overlay mode, the cam parameter should be null.
Your answer
 
             Follow this Question
Related Questions
OnDrag methods not being called on Android in Unity 2018.3.5f1 3 Answers
UI drag and drop 1 Answer
Can I use EventSystem + InputModule to implement scroll via button? 0 Answers
Insane EventSystem.Update lag spike, no graphic raycasters in scene 3 Answers
EventSystem.SetSelectedGameObject Does not display highlight animations for my buttons 1 Answer