I watched a tutorial on YT (From unity 4) of making a score in a simple game, i writed a short script (Like in this tutorial) = #pragma strict
static var currentScore : int = 0;
var offsetY : float = 40;
var sizeX : float = 100;
var sizeY : float = 25;
function OnGUI ()
{
GUI.Box (new Rect (Screen.height*0.5, Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "Score: " + currentScore);
}
Then I got an error = Assets/GameMaster.js(11,18): BCE0024: The type ‘UnityEngine.Rect’ does not have a visible constructor that matches the argument list ‘(float, float, float, float, float)’.
Please solve my problem (:
Photo of script: Click
Hi there @Banankorrrr
A rect’s class constructor can only take in 4 parameters, these are as follows:
var myRect = new Rect(x, y, width, height);
As you can see, it requires an x and y value, along with the height and position. Looking at your code we can see that you have 5 parameters passed into the Rect’s constructor. Shown below:
GUI.Box (new Rect (Screen.height*0.5, Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "Score: " + currentScore)
To fix your error you will have to remove or re-position one of your extra parameters. So for example, something like this:
GUI.Box (new Rect (Screen.height*0.5, Screen.width/2-sizeX/2, offsetY, sizeX), "Score: " + currentScore);
That will then remove the error, but the position of your box may be out of place. Try looking at the tutorial again and see if you miss-placed a comma or accidentally added another variable where you were not supposed to. Also, see the linked scripting reference below for a Rect’s constructor.
I hope this helps!
Rect Constructor - Unity Scripting API