我在統一場景中有一個文本框。在這個問題上,文本框已經有幾行單獨的文本。統一文本框拒絕用c#腳本更新
的腳本如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class GameEngine : MonoBehaviour {
//Game level variables:
public bool TutorialDone = false;
public int TutorialCount = 0;
bool isticking = false;
Text outputtext;
// Use this for initialization
void Start() {
outputtext = GameObject.Find("ConsoleOutputScroll/Viewport/Output").GetComponent<Text>();
}
// Update is called once per frame
void Update() {
}
//Process inputted text and splits into commands, validation etc.
public void processtext(string inputstring)
{
if(inputstring == "")
{
commandin("blank");
return;
}
commandin("something");
return;
}
//Process any commands supplied, apply these to game stages
public void commandin(string commandtype)
{
if(TutorialDone == false)
{
tutorialrun();
return;
}
}
//Tutorial procedure
public void tutorialrun()
{
switch (TutorialCount)
{
case 0:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 1:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 2:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 3:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 4:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 5:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 6:
TutorialCount++;
tickertypenewline("ESTABLISHING CONNECTION...");
break;
}
}
//Appends to the console output on a new line
public void outputnewline(string inputstring)
{
string Temp;
Temp = outputtext.text + inputstring + Environment.NewLine;
outputtext.text = Temp;
}
//Clears output and adds new text
public void outputclear(string inputstring)
{
outputtext.text = inputstring + Environment.NewLine;
}
//Typewriter style text addition on a new line
public void tickertypenewline(string inputstring)
{
//Exit if we are already ticking
if (isticking)
{
return;
}
isticking = true;
StartCoroutine(tickertypeco(inputstring));
}
//Typewriter style text after clearing output
public void tickertypeclear(string inputstring)
{
outputtext.text = "";
StartCoroutine(tickertypeco(inputstring));
}
//Typewriter generator
IEnumerator tickertypeco(string inputstring)
{
//outputtext.text = "sugar";
WaitForSeconds waitTime = new WaitForSeconds(0.125f);
foreach (char c in inputstring)
{
string temp = outputtext.text + c.ToString();
outputtext.text = temp;
yield return waitTime;
}
isticking = false;
}
這只是似乎沒有做任何事情。如果我事先清除了文本框,它似乎沒有做任何事情。但是,如果我清除並添加一個沒有任何新行或空格的隨機字符串,則表現正確。結果應該是字符串輸入文本框時的類型化效果。
似乎無法解決故障與此有關。
有人可以幫忙嗎? :)
程序員:):您的重做代碼在那裏,我只改變了從tickerText到outputtext的名稱。它仍然不起作用,現在我已經包含了整個GameEngine腳本,希望你能在那裏發現一些我已經錯過的東西。 :)。非常感謝您繼續關注我。
感謝您的。我更新了我的代碼並編輯了我的問題。不幸的是,它仍然無法正常工作。 –
您的更新代碼是**不是**我的代碼。請解決這個問題。看看'tickertypeco'函數,它們仍然不同於我的。另外,爲什麼不創建新的腳本,將我的代碼複製到它,禁用其他腳本,然後嘗試它,看看會發生什麼。如果它工作,然後修改它並添加你的其他代碼。 – Programmer
感謝那位程序員。我比較了兩種功能,除了不同的命名外,它們是相同的。我已經使用「outputtext」而不是「tickerText」等。唯一的區別是在函數的末尾添加了一個新行。如上所述,這只是嘗試並進一步調查問題。這不再存在。 –