I’m trying to make this function work in js, but I’m getting an error with the last argument of the function. Here is my code:
var point : Vector2;
print(RectTransformUtility.ScreenPointToLocalPointInRectangle(timelineObj, Input.mousePosition, null, point));
I get the error “The best overload for the method ‘UnityEngine.RectTransformUtility.ScreenPointToLocalPointInRectangle(UnityEngine.RectTransform, UnityEngine.Vector2, UnityEngine.Camera, ref UnityEngine.Vector2)’ is not compatible with the argument list ‘(UnityEngine.GameObject, UnityEngine.Vector3, null, UnityEngine.Vector2)’.”.
I have tried putting “out” before the point variable but then it tells me “expecting ), found ‘point’.”.
The documentation does not give an example of how to use this function in js, so I am confused as to what I am doing wrong.
Not out, but ref. Like ScreenPointToLocalPointInRectangle(timelineObj, Input.mousePosition, Camera.main, ref point);
Most likely it sets values of ref variable, so act accordingly.
Ohhh riiight. The problem was different. It’s not like you need ref or out(UnityScript doesn’t have them); You’re supplying first argument a GameObject instead of expected RectTransform.
So it should look
var rectTransform = timelineObj.GetComponent(RectTransform);
var point : Vector2;
UnityEngine.RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Camera.main, point);
At least that compiles for me. You might want to check if(rectTransform==null) and do something like error or not doing anything then.