简体   繁体   English

统一3D错误如何解决

[英]unity 3d error how to fix it

I am starting my project and i got this error can't figure out what's wrong with it. 我正在开始我的项目,但我收到此错误无法弄清楚它出了什么问题。 Really appreaciate help and sorry if it's stupid question. 非常感谢您的帮助,如果这是一个愚蠢的问题,请对不起。 I am still new at unity. 我仍然团结一致。 Thanks for all the answers. 感谢所有的答案。

I tried searching for help about this vector2(width,height) but to me it looks all fine. 我尝试搜索有关此vector2(width,height)的帮助,但对我来说一切正常。 And also if anyone can please explain to my about this rect.center problem why did i got it? 而且,如果有人可以向我解释这个rec​​t.center问题,为什么会得到它?

Unity3d Error: Unity3d错​​误:

Assets/Scenes/Game/Scripts/GUI/GameGUI.cs(22,22): error CS1061: Type `UnityEngine.Rect' does not contain a definition for `center' and no extension method `center' of type `UnityEngine.Rect' could be found (are you missing a using directive or an assembly reference?)

Code: 码:

using UnityEngine;
using System.Collections;

public class GameGUI : MonoBehaviour {


    void OnResume() {
        enabled = true;
    }

    void OnPause() {
        enabled = false;
    }


    void OnGUI() {
        int fps = (int) (1f/Time.deltaTime*Time.timeScale);
        GUILayout.Box( "FPS "+fps );

        Vector2 size = GUI.skin.label.CalcSize( new GUIContent("+") );
        Rect rect = new Rect(0, 0, size.x, size.y);
        rect.center = new Vector2(Screen.width, Screen.height)/2f;
        GUI.Label( rect, "+" );
    }


}

Thank you for your time. 感谢您的时间。

The center property was introduced in Unity 3.5 according to Unity's Script Reference History page. 根据Unity的“脚本参考历史”页面,在Unity 3.5中引入了center属性 . So you have to calculate the center on your own. 因此,您必须自己计算中心。 Maybe your constructor should look something like this: 也许您的构造函数应如下所示:

Rect rect = new Rect(Screen.width/2f, Screen.height/2f, size.x, size.y);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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