我正在开始我的项目,但我遇到了这个错误,无法弄清楚它有什么问题。如果这是愚蠢的问题,真的很感激帮助和抱歉。我还是个新人。感谢所有的答案。
我尝试搜索有关此 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, "+" );
}
}
感谢您的时间。