【问题标题】:unity 3d error how to fix itunity 3d 错误如何解决
【发布时间】:2013-05-06 11:50:01
【问题描述】:

我正在开始我的项目,但我遇到了这个错误,无法弄清楚它有什么问题。 如果这是愚蠢的问题,真的很感激帮助和抱歉。我还是个新人。谢谢大家的回答。

我尝试搜索有关此 vector2(width,height) 的帮助,但在我看来一切都很好。 另外,如果有人可以向我解释一下这个 rect.center 问题,我为什么会得到它?

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?)

代码:

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, "+" );
    }


}

感谢您的宝贵时间。

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    center 属性是根据Unity's Script Reference History page. 在 Unity 3.5 中引入的。所以你必须自己计算中心。也许你的构造函数应该是这样的:

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

    【讨论】:

      猜你喜欢
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多