Hi all, well I’m trying to implement part of the code of the ObjectLabel example from unifycommunit, here it is:
if (clampToScreen) {
var relativePosition =Camera.main.transform.InverseTransformPoint(target.transform.position);
relativePosition.z = Mathf.Max(relativePosition.z, 1.0);
thisTransform.position = Camera.main.WorldToViewportPoint(Camera.main.transform.TransformPoint(relativePosition + offset));
//thisTransform.position = Camera.main.WorldToViewportPoint(target.transform.position + offset);
thisTransform.position = Vector3(Mathf.Clamp(thisTransform.position.x, clampBorderSize, 1.0-clampBorderSize), Mathf.Clamp(thisTransform.position.y, clampBorderSize, 1.0-clampBorderSize), thisTransform.position.z);
}
}
else {
thisTransform.position =Camera.main.WorldToViewportPoint(target.transform.position + offset);
}
The problem seems to be in "clampToScreen" if i do a Debug.Log(relativePosition) right after " var relativePosition =Camera.main.transform.InverseTransformPoint(target.transform.localPosition);
" the result is: (0.0,0.0,0.0)
The position of the Camera: (48242,9, 1035,4, 52354,5) and the target position: (47409,3, 88,7, 52738,0)
Any clue what could be the problem?
Thanks in advance.