Helpp !! Can't draw the rectangle on the gameobject 's positon
I tried everything,,drawing onGui,vectrocity,and other things i can't !! I converted from screenplace to world space and the opposite i did everything !! The rectangle isn't at the same position as the gameobject,what i am doing wrong??
public class Utils:MonoBehaviour { static Texture2D _whiteTexture; public float x, y, z, h; Vector3 convert; public Camera cam; public RectTransform gm; public static Texture2D WhiteTexture { get { if (_whiteTexture == null) { _whiteTexture = new Texture2D(1, 1); _whiteTexture.SetPixel(0, 0, Color.white); _whiteTexture.Apply(); } return _whiteTexture; } } static void DrawScreenRect(Rect rect, Color color) { GUI.color = color; GUI.DrawTexture(rect, WhiteTexture); GUI.color = Color.white; } void OnGUI() { Debug.Log(x); Debug.Log(y); //Vector4 Trial=cam.ScreenToWorldPoint() Vector3 screenPos = Camera.main.ScreenToWorldPoint(gm.position); Vector2 guiPosition = new Vector2(screenPos.x , screenPos.y); Debug.Log(guiPosition); Debug.Log(gm.position); Utils.DrawScreenRect(new Rect(gm.position.x,gm.position.y, z, h), Color.green); Debug.Log(transform.position); } }