0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

コルーチンの書き方がうまくいかずエラーが出てしまいます

Posted at

Unityを使ってノベルゲームの制作に挑戦しているのですが1文字ずつ表示させるためのコルーチンでエラーが出てしまいます。エラーは
Assets\Scripts\Story\WriteTxt.cs(23,29): error CS0120: An object reference is required for the non-static field, method, or property 'WriteTxt.Timer()'
です。
コルーチン部分をコメント化すると正常に作動するのでたぶんコルーチン部分が間違っていると思うのですがアドバイスをお願いします。
Unityのバージョンは2019.3.71.fです。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//文字送りに必要な者たち
using UnityEngine.UI;
using System.Text.RegularExpressions;

public class WriteTxt : MonoBehaviour
{
public static void Write_Txt(int num)
{
//表示中の文字数を示す変数
int msg_count=0;

    //メッセージの初期化
    MnageSt.messageText.text="";

    while(MnageSt.senario[num].Length>msg_count)
    {
        MnageSt.messageText.text+=MnageSt.senario[num][msg_count];
        msg_count++;
        StartCoroutine (Timer());
    }
} 

IEnumerator Timer () {
    yield return new WaitForSeconds (1);
}

}

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?