String.Format();
String.Replace("一", "二");
将String字符串中 “一” 全部替换成 “二”。
public class TextType : MonoBehaviour {
int i = 0;
public float charsPerSeconds = 0.2f;
private string content;
private Text textTest;
private float timer;
private int currentPos;
private bool isActive;
// Use this for initialization
void Start () {
textTest = GetComponent <Text> ();
}
// Update is called once per frame
void Update () {
if (isActive == true){
StartTyperEffect ();
}
}
public void TyperEffect(){
isActive = true;
}
private void StartTyperEffect() {
timer += Time.deltaTime;
if (timer > charsPerSeconds) {
timer -= charsPerSeconds;
currentPos++;
textTest.text = content.Substring (0, currentPos);
if(currentPos >= content.Length) {
FinishTyperEffect ();
}
}
}
private void FinishTyperEffect() {
isActive = false;
timer = charsPerSeconds;
currentPos = 0;
textTest.text = content;
}
void OnEnable()
{
textTest = GetComponent<Text>();
if (i == 0)
{
content = textTest.text;
i++;
}
textTest.text = "";
timer = charsPerSeconds;
isActive = true;
currentPos = 0;
}
}