Unity文字游戏开发日志(1)—— 打字机效果

作者是一名OIer,因为兴趣,想在寒假期间开发一款文字游戏的demo。

本博客仅用作记录,马蜂极度不符合规范。

但是,可以用来避坑。

1.等待功能——使用的是协程函数,且调用与常规调用函数不同。

 private IEnumerator Sco(){
        isScoelling = 1;
        senten.text = "";
        foreach(char letter in dialog[dires].ToCharArray()){
            senten.text += letter;
            yield return new WaitForSeconds(textspeed);//等待多久
        }
        isScoelling = 0;
   }




StartCoroutine(你要用的函数);//调用
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;

public class bplan : MonoBehaviour
{
    // Start is called before the first frame update
    public TMP_Text  senten;
    public float textspeed;
    string[] dialog = new string[1001] ;
    int tot = 0;
    void add(string a){
        dialog[tot] = a;
        tot++;
    }
    void Start()
    {
        TextAsset txt = Resources.Load("test01") as TextAsset;
        //Debug.Log(txt);
        dialog = txt.text.Split('\n');
    }

    // Update is called once per frame
    int dires = 0;
    int isScoelling = 0;
    private IEnumerator Sco(){
        isScoelling = 1;
        senten.text = "";
        foreach(char letter in dialog[dires].ToCharArray()){
            senten.text += letter;
            yield return new WaitForSeconds(textspeed);
        }
        isScoelling = 0;
    }
    void Update () {
            if (Input.GetKeyUp(KeyCode.A)&&isScoelling == 0)
            {
            
            dires++;
            StartCoroutine(Sco());
            
            }
    }
}

相关推荐

  1. Unity文字游戏开发日志1)—— 打字机效果

    2024-01-19 07:00:03       36 阅读
  2. Unity文字游戏开发日志(2)——存档与读档

    2024-01-19 07:00:03       33 阅读
  3. Unity Text文本实现打字机(一个一个出来)的效果

    2024-01-19 07:00:03       32 阅读
  4. unity text 文本符号显示问题与打字机效果的结合

    2024-01-19 07:00:03       22 阅读
  5. 合作测试开发日志1

    2024-01-19 07:00:03       18 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-19 07:00:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-19 07:00:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-19 07:00:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-19 07:00:03       20 阅读

热门阅读

  1. Mysql核心知识命令汇总

    2024-01-19 07:00:03       35 阅读
  2. bevy the book 20140118翻译(全)

    2024-01-19 07:00:03       30 阅读
  3. 【中断之GPT问答】

    2024-01-19 07:00:03       28 阅读
  4. Oracle中的索引

    2024-01-19 07:00:03       31 阅读
  5. Django笔记(四):视图views

    2024-01-19 07:00:03       34 阅读
  6. Linux 使用PS命令掌握进程管理

    2024-01-19 07:00:03       37 阅读
  7. jmeter的使用教程

    2024-01-19 07:00:03       32 阅读
  8. Spring 核心之 IOC 容器学习二

    2024-01-19 07:00:03       25 阅读
  9. 自定义Dubbo RPC通信协议

    2024-01-19 07:00:03       20 阅读