简体   繁体   中英

Errors in Unity3d

Here are the errors I'm getting in the Unity console:

Assets/leavingPlayableAreaScript.cs(16,74): error CS1729: The type 'UnityEngine.Rect' does not contain a constructor that takes '3' arguments

Assets/leavingPlayableAreaScript.cs(16,21): error CS1502: The best overloaded method match for `UnityEngine.GUI.DrawTexture(UnityEngine.Rect, UnityEngine.Texture)' has some invalid arguments

Assets/leavingPlayableAreaScript.cs(16,21): error CS1503: Argument '#1' cannot convert 'object' expression to type 'UnityEngine.Rect'

Here is my code:

using UnityEngine;
using System.Collections;

public class leavingPlayableAreaScript : MonoBehaviour
{
    public GUIStyle Stylesheet;
    public bool inTrigger;

    void Update () {
    }

    void OnGUI()
    {
        GUI.DrawTexture(new Rect((Screen.width/2) -600, 500, 800), Stylesheet);
    }
}

The error is self-explanatory.

The type 'UnityEngine.Rect' does not contain a constructor that takes '3' arguments.

You're missing an argument:

Rect(left: float, top: float, width: float, height: float)

https://docs.unity3d.com/Documentation/ScriptReference/Rect-ctor.html

Here's a proper example from documentation:

// Draws a texture on the screen at 10, 10 with 100 width, 100 height.
var aTexture : Texture;
function OnGUI() {
    if(Event.current.type.Equals(EventType.Repaint))
        Graphics.DrawTexture(Rect(10, 10, 100, 100), aTexture);
}

https://docs.unity3d.com/Documentation/ScriptReference/Graphics.DrawTexture.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM