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());
            
            }
    }
}

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值