Component.guiText已过时所导致的代码错误

lzd23722086 2017-07-29 06:44:43
代码功能为一个卡牌翻转游戏设置一个定时器
代码如下,报错处我放了一个表情,错误为Component.guiText已过时:
using System.Collections;
using UnityEngine;

public class ClockScript : MonoBehaviour {
private bool clockIsPaused = false;
private float startTime;//(in seconds)
private float timeRemaining;//(in seconds)
private float percent;
public Texture2D clockBG;
public Texture2D clockFG;
private float clockFGMaxWidth;//the starting width of the foreground bar
public Texture2D rightSide;
public Texture2D leftSide;
public Texture2D back;
public Texture2D blocker;
public Texture2D shiny;
public Texture2D finished;

private void Awake()
{
startTime = Time.time + 120.0f;
clockFGMaxWidth = clockFG.width;
}

private void Update()
{
if (!clockIsPaused)
{
//make sure the timer is not paused
DoCountdown();
}
}
private void DoCountdown()
{
timeRemaining = startTime - Time.time;
percent = timeRemaining / startTime * 100;
if (timeRemaining < 0)
{
timeRemaining = 0;
clockIsPaused = true;
TimeIsUp();
}
ShowTime();
//Debug.Log("time remaining = " + timeRemaining);
}

private void PauseClock()
{
clockIsPaused = true;
}

private void UnpauseClock()
{
clockIsPaused = false;
}

private void ShowTime()
{
int minutes;
int seconds;
string timeStr;
minutes = (int)(timeRemaining / 60);
seconds = (int)(timeRemaining % 60);
timeStr = minutes.ToString() + ":";
timeStr += seconds.ToString("D2");
guiText.text = timeStr;//display the time to the GUI
}
private void TimeIsUp()
{
Debug.Log("Time is up!");
}

private void OnGUI()
{
int pieClockX = 100;
int pieClockY = 50;
int pieClockW = 64;//clock width
int pieClockH = 64;//clock height

int pieClockHalfW = (int)(pieClockW * 0.5);//half the clock width
int pieClockHalfH = (int)(pieClockH * 0.5);//half the clock height
bool isPastHalfway = percent < 50;
Rect clockRect = new Rect(pieClockX, pieClockY, pieClockW, pieClockH);
float rot = (percent / 100) * 360;
Vector2 centerPoint = new Vector2(pieClockX + pieClockHalfW, pieClockY + pieClockHalfH);

Matrix4x4 startMatrix = GUI.matrix;
GUI.DrawTexture(clockRect, back, ScaleMode.StretchToFill, true, 0);

if (isPastHalfway)
{
GUIUtility.RotateAroundPivot(-rot - 180, centerPoint);
GUI.DrawTexture(clockRect, leftSide, ScaleMode.StretchToFill, true, 0);
GUI.matrix = startMatrix;
GUI.DrawTexture(clockRect, blocker, ScaleMode.StretchToFill, true, 0);
}
else {
GUIUtility.RotateAroundPivot(-rot, centerPoint);
GUI.DrawTexture(clockRect,rightSide, ScaleMode.StretchToFill, true, 0);
GUI.matrix = startMatrix;
GUI.DrawTexture(clockRect, leftSide, ScaleMode.StretchToFill, true, 0);
}
if (percent < 0)
GUI.DrawTexture(clockRect, finished, ScaleMode.StretchToFill, true, 0);
GUI.DrawTexture(clockRect, shiny, ScaleMode.StretchToFill, true, 0);
//this is the width that the foreground bar should be
float newBarWidth = (percent / 100) * clockFGMaxWidth;
int gap = 20;//a spacing variable to help us position the clock
GUI.BeginGroup(new Rect(Screen.width - clockBG.width - gap, gap, clockBG.width, clockBG.height));
GUI.DrawTexture(new Rect(0, 0, clockBG.width, clockBG.height), clockBG);
GUI.BeginGroup(new Rect(5,6, newBarWidth, clockFG.height));
GUI.DrawTexture(new Rect(0, 0, clockFG.width, clockFG.height), clockFG);
GUI.EndGroup();
GUI.EndGroup();


}
}
项目的目录结构如下图:
...全文
2583 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
LoveMollyWendy 2017-08-10
  • 打赏
  • 举报
回复
用GUI.Label代替不就完啦,显示下就行,不行就用UGUI Text代替

2,543

社区成员

发帖
与我相关
我的任务
社区描述
Unity3D相关内容讨论专区
游戏unity 技术论坛(原bbs)
社区管理员
  • Unity3D
  • 芝麻粒儿
  • 「已注销」
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

Unity3D社区公告:

  1. 社区致力于解决各种Unity3D相关的“疑难杂症”。
  2. 社区不允许发布与Unity3D或相关技术无关内容。
  3. 社区版主邀请各位一道为打造优秀社区不懈努力。

试试用AI创作助手写篇文章吧