Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I keep getting CS7036 on line 22 and 35

I know that this is pretty simple for others but, I don’t know why I keep Getting the error saying

there is no argument given that corresponds to the required parameter width of Rect.Rect(float, float, float, float)

when compiling even though I just need the position and the size so that I can render a white line. sorry, I’m still new to coding C#

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

using System;
using UnityEngine;

public class Render
{
    public static GUIStyle StringStyle { get; set; } = new GUIStyle(GUI.skin.label);

    public static Color Color
    {
        get { return GUI.color; }
        set { GUI.color = value; }
    }

    public static void DrawBox(Vector2 position, Vector2 size, Color color, bool centered = true)
    {
        Color = color;
        DrawBox(position, size, centered);
    }
    public static void DrawBox(Vector2 position, Vector2 size, bool centered = true)
    {
        var upperLeft = centered ? position - size / 2f : position;
        GUI.DrawTexture(new Rect(position, size), Texture2D.whiteTexture, ScaleMode.StretchToFill);
    }

    public static void DrawString(Vector2 position, string label, Color color, bool centered = true)
    {
        Color = color;
        DrawString(position, label, centered);
    }
    public static void DrawString(Vector2 position, string label, bool centered = true)
    {
        var content = new GUIContent(label);
        var size = StringStyle.CalcSize(content);
        var upperLeft = centered ? position - size / 2f : position;
        GUI.Label(new Rect(upperLeft, size), content);
    }

    public static Texture2D lineTex;
    public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width)
    {
        Matrix4x4 matrix = GUI.matrix;
        if (!lineTex)
            lineTex = new Texture2D(1, 1);

        Color color2 = GUI.color;
        GUI.color = color;
        float num = Vector3.Angle(pointB - pointA, Vector2.right);

        if (pointA.y > pointB.y)
            num = -num;

        GUIUtility.ScaleAroundPivot(new Vector2((pointB - pointA).magnitude, width), new Vector2(pointA.x, pointA.y + 0.5f));
        GUIUtility.RotateAroundPivot(num, pointA);
        GUI.DrawTexture(new Rect(pointA.x, pointA.y, 1f, 1f), lineTex);
        GUI.matrix = matrix;
        GUI.color = color2;
    }

    public static void DrawBox(float x, float y, float w, float h, Color color, float thickness)
    {
        DrawLine(new Vector2(x, y), new Vector2(x + w, y), color, thickness);
        DrawLine(new Vector2(x, y), new Vector2(x, y + h), color, thickness);
        DrawLine(new Vector2(x + w, y), new Vector2(x + w, y + h), color, thickness);
        DrawLine(new Vector2(x, y + h), new Vector2(x + w, y + h), color, thickness);
    }

    public static void DrawBoxOutline(Vector2 Point, float width, float height, Color color, float thickness)
    {
        DrawLine(Point, new Vector2(Point.x + width, Point.y), color, thickness);
        DrawLine(Point, new Vector2(Point.x, Point.y + height), color, thickness);
        DrawLine(new Vector2(Point.x + width, Point.y + height), new Vector2(Point.x + width, Point.y), color, thickness);
        DrawLine(new Vector2(Point.x + width, Point.y + height), new Vector2(Point.x, Point.y + height), color, thickness);
    }
}

I tried doing this

public static void DrawString(Vector2 position, string label, bool centered = true)
{
    var content = new GUIContent(label);
    var size = StringStyle.CalcSize(content);
    var upperLeft = centered ? position - size / 2f : position;
    GUI.Label(new Rect(upperLeft.x, upperLeft.y, size.x, size.y), content);
}

and then this

public static void DrawBox(Vector2 position, Vector2 size, bool centered = true)
{
var upperLeft = centered ? position - size / 2f : position;
float width = size.x; // Assuming size is a Vector2
float height = size.y; // Assuming size is a Vector2
GUI.DrawTexture(new Rect(position.x, position.y, width, height), Texture2D.whiteTexture, ScaleMode.StretchToFill);
}

it compiled, but whenever i call it, nothing happens.

>Solution :

In DrawBox you do this:
GUI.DrawTexture(new Rect(position, size), Texture2D.whiteTexture, ScaleMode.StretchToFill);

The constructor of Rect needs 4 floats

So you want to do something like this instead:

GUI.DrawTexture(new Rect(position.x, position.y, size.x,size.y), Texture2D.whiteTexture, ScaleMode.StretchToFill);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading