Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么这段代码要删掉文本中的最后一行?_C#_Unity3d_User Interface_Text - Fatal编程技术网

C# 为什么这段代码要删掉文本中的最后一行?

C# 为什么这段代码要删掉文本中的最后一行?,c#,unity3d,user-interface,text,C#,Unity3d,User Interface,Text,在下面的文件中,我使用视频在屏幕上制作打字机效果。我现在对它有点意见。 无论出于何种原因,每当我使用它时,它都会将最后一个字母切掉(例如,输入“Hello there”并输入“Hello there”)。你知道为什么会这样吗 我正在使用的编程是一个经过修改的版本,以适合我的游戏: using UnityEngine; using System.Collections; using UnityEngine.UI; public class TypeWriterEffect : MonoBehav

在下面的文件中,我使用视频在屏幕上制作打字机效果。我现在对它有点意见。
无论出于何种原因,每当我使用它时,它都会将最后一个字母切掉(例如,输入“Hello there”并输入“Hello there”)。你知道为什么会这样吗

我正在使用的编程是一个经过修改的版本,以适合我的游戏:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TypeWriterEffect : MonoBehaviour {

public float delay = 0.1f;
public float startDelay = 0f;
public string fullText;
public bool showGameHS;
public bool showTotalScore;
public string totalGameScore;
private string currentText = "";

// Use this for initialization
void Start () {
    totalGameScore = PlayerPrefs.GetString("totalGameScore"); // total score throughout the game
    if (showTotalScore)
    {
        fullText = TimerScript.fullScore.ToString() + "."; // a "." is added to fix this issue
    }
    else if (showGameHS) // the local highscore
    {
        fullText = totalGameScore + "."; // a "." is added to fix this issue
    }
    StartCoroutine(ShowText());
}

IEnumerator ShowText(){
    yield return new WaitForSeconds(startDelay); // this was added on as a basic start delay

    for (int i = 0; i < fullText.Length; i++){
        currentText = fullText.Substring(0,i);
        this.GetComponent<Text>().text = currentText;
        yield return new WaitForSeconds(delay);
    }
}
使用UnityEngine;
使用系统集合;
使用UnityEngine.UI;
公共类TypeWriteEffect:MonoBehavior{
公共浮动延迟=0.1f;
公共浮动起始时间=0f;
公共字符串全文;
公共场所展示游戏;
公共布尔显示总分;
公共字符串总游戏分数;
私有字符串currentText=“”;
//用于初始化
无效开始(){
totalGameScore=PlayerPrefs.GetString(“totalGameScore”);//整个游戏的总分
如果(显示总分)
{
fullText=TimerScript.fullScore.ToString()
}
else if(showGameHS)//本地高分
{
全文=totalGameScore+“;//a.”已添加以修复此问题
}
start例程(ShowText());
}
IEnumerator ShowText(){
yield return new WaitForSeconds(startDelay);//这是作为基本启动延迟添加的
for(int i=0;i

}您的
for
循环正在从
0
循环到
Length-1
。然后使用此变量告诉
子字符串
要返回的字符数。它第一次返回0个字符。最后,它返回除最后一个字符以外的所有字符

您可以在length参数中添加1,也可以更改
for
循环的边界:

for (int length = 1; length <= fullText.Length; length++){
    currentText = fullText.Substring(0, length);
    this.GetComponent<Text>().text = currentText;
    yield return new WaitForSeconds(delay);
}

for(int-length=1;length
i
始终在字符串的完整长度之前停止一个索引->最后一个符号的子字符串剪切