我开始我的项目,我得到这个错误无法弄清楚它有什么问题。 如果是愚蠢的问题,真的非常不满意帮助和抱歉。我仍然是新的团结。感谢所有的答案。统一3d错误如何解决它
我试过寻找关于这个vector2(宽度,高度)的帮助,但对我来说它看起来一切正常。 如果有人可以向我解释这个问题,为什么我得到它?
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, "+");
}
}
谢谢您的时间。
问题不在于Vector2。错误表示Rect类没有一个名为center的变量。但是,它的确有(http://docs.unity3d.com/Documentation/ScriptReference/Rect-center.html)。 也许,正如错误消息所说,你错过了一个参考?你也试过右键单击Rect类的名字,然后选择“转到定义”,看看该变量是否存在于类中?也许你使用的是旧版本的Unity,试着检查一下? – Renan 2013-05-06 11:59:40
我在Unity 3.5.6下创建了一个测试类GameGUI,它编译没有错误。必须是一些设置。奇怪 – Kay 2013-05-06 12:00:07
嗯,我的版本是3.2我认为。我使用UniScite,所以我没有“定义”这样的功能。 – karolis 2013-05-06 12:08:06