質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

2723閲覧

TextMeshProのページ送りについて

kagiyama

総合スコア10

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/01/24 15:18

前提・実現したいこと

UnityでRPGを作っています。
モブキャラクターに接触したらウィンドウが現れ、テキストが一文字ずつ配置されるという機能を実装するため色々と試してみましたがうまくいきません。
最終的に
http://baba-s.hatenablog.com/entry/2017/12/22/120100
https://www.slideshare.net/UnityTechnologiesJapan/unity2017text-meshpro
などを参考にして下記のコードを書いたのですが、初心者ゆえSetPage(page);をどう記述したらいいのかわかりません。

どうかご教授願います。

発生している問題・エラーメッセージ

現在のコンテキストに'SetPage'という名前は存在しません。

該当のソースコード

C#

1 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using TMPro; 6using RedBlueGames.Tools.TextTyper; 7 8public class TextController : MonoBehaviour { 9 10 public TextMeshProUGUI TextMeshProUGUI; 11 public TextTyper textTyper; 12 13 GameObject objectA; 14 CharaEventController script; 15 16 public bool talkingflag = false; 17 18 GameObject Text; 19 20 string setText; 21 22 GameObject window; 23 UnityEngine.UI.Image windowComponent; 24 25 int pageCount; 26 27 bool isTyping; 28 29 bool isCalled = false; 30 31 32 void Start() 33 { 34 talkingflag = false; 35 36 objectA = GameObject.Find("objectA"); 37 script = objectA.GetComponent<CharaEventController>(); 38 39 Text = GameObject.Find("TextMeshPro Text"); 40 TextMeshProUGUI = Text.GetComponent<TextMeshProUGUI>(); 41 pageCount = TextMeshProUGUI.textInfo.pageCount; 42 43 window = GameObject.Find("window"); 44 windowComponent = window.GetComponent<UnityEngine.UI.Image>(); 45 46 } 47 48 49 void Update() 50 { 51 talkingflag = script.TalkFlag; 52 53 if (talkingflag == true) 54 { 55 TextMeshProUGUI.enabled = true; 56 windowComponent.enabled = true; 57 if (isCalled == false) 58 { 59 isCalled = true; 60 Moji(); 61 } 62 } 63 64 else 65 { 66 TextMeshProUGUI.enabled = false; 67 windowComponent.enabled = false; 68 } 69 70 71 72 } 73 74 void Moji() 75 { 76 Text = GameObject.Find("TextMeshPro Text"); 77 textTyper = Text.GetComponent<TextTyper>(); 78 isTyping = textTyper.IsTyping; 79 setText = ("<delay=0.25>テキスト1<page>テキスト2</delay>"); 80 81 textTyper.TypeText(setText); 82 83 if (Input.GetMouseButtonUp(0)) 84 { 85 NextPage(); 86 87 if (isTyping == false) 88 { 89 textTyper.Skip(); 90 } 91 92 } 93 } 94 95 public void NextPage() 96 { 97 int page = TextMeshProUGUI.pageToDisplay; 98 page++; 99 if(page > pageCount) 100 { 101 page = pageCount; 102 } 103    SetPage(page); 104 105 } 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121} 122 123 124 125 126 127 128 129 130 131 132 133 134

補足情報(FW/ツールのバージョンなど)

Unity5.6.6f2 Personal(32bit版)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kagiyama

2019/01/26 17:01

ありがとうございます!おかげさまで解決することができました! 本当に助かりました。重ね重ねありがとうございます。
sakura_hana

2019/01/28 01:08

解決して良かったです。同様の問題を抱えている人の為、解決方法を自己回答してベストアンサーにしてもらえれば幸いです。
kagiyama

2019/02/12 10:11

ありがとうございます。 遅くなってすみません。初心者過ぎて回答システムに関して色々と誤解しておりました。 これからおっしゃっていただいた通りにします。このたびはありがとうございました。
guest

回答1

0

自己解決

ヒントを頂いてからまた紆余曲折あり、結局TextTyperのサンプルを参考に以下の形になりました。

C#

1namespace RedBlueGames.Tools.TextTyper 2{ 3 using UnityEngine; 4 using System.Collections; 5 using System.Collections.Generic; 6 using RedBlueGames.Tools.TextTyper; 7 using UnityEngine.UI; 8 using TMPro; 9 using UnityEngine.EventSystems; 10 11 public class TalkController : MonoBehaviour 12 { 13 GameObject mob; 14 CharaEventController script; 15 public bool talkingflag = false; 16 17 [Header("UI References")] 18 [SerializeField] 19 private AudioClip printSoundEffect; 20 21 [SerializeField] private TMP_Text text; 22 23 public Queue<string> dialogueLines = new Queue<string>(); 24 25 [SerializeField] 26 [Tooltip("The text typer element to typing with")] 27 28 private TextTyper TextTyper; 29 30 public void Start() 31 { 32 this.TextTyper.CharacterPrinted.AddListener(this.HandleCharacterPrinted); 33 mob = GameObject.Find("mob"); 34 script = e2b.GetComponent<CharaEventController>(); 35 36 dialogueLines.Enqueue("テキスト1"); 37 dialogueLines.Enqueue("テキスト2 "); 38 } 39 40 public void Update() 41 { 42 if (script == null) 43 { 44 talkingflag = false; 45 } 46 47 else 48 { 49 talkingflag = script.TalkFlag; 50 } 51 52 if (Mathf.Approximately(Time.timeScale, 0f)) 53 { 54 return; 55 } 56 57 if (talkingflag == true) 58 { 59 ShowScript(); 60 return; 61 } 62 63 } 64 65 66 public void OnPointerClick(PointerEventData pointerData) 67 { 68 ShowScript(); 69 } 70 71 private void ShowScript() 72 { 73 if (Input.GetMouseButtonDown(0)) 74 { 75 if (dialogueLines.Count <= 0) 76 { 77 return; 78 } 79 80 this.TextTyper.TypeText(dialogueLines.Dequeue()); 81 } 82 83 } 84 85 private void HandleCharacterPrinted(string printedCharacter) 86 { 87 // Do not play a sound for whitespace 88 if (printedCharacter == null || printedCharacter == " " || printedCharacter == "\n") 89 { 90 return; 91 } 92 93 var audioSource = this.GetComponent<AudioSource>(); 94 if (audioSource == null) 95 { 96 audioSource = this.gameObject.AddComponent<AudioSource>(); 97 } 98 99 audioSource.clip = this.printSoundEffect; 100 audioSource.Play(); 101 } 102 } 103} 104

これを空のゲームオブジェクトにアタッチして、ウィンドウなどのUI、TextMeshProのTextと一緒にプレハブ化して、以下のスクリプトで出現と消去を管理するようにしました。
(参考:https://gametukurikata.com/program/stop)

C#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class TextControllers : MonoBehaviour { 6 7 [SerializeField] 8 private GameObject talkUIPrefab; 9 private GameObject talkUIInstance; 10 11 public Transform Parent; 12 13 public GameObject Mob; 14 public CharaEventController script; 15 16 public bool talkingflag = false; 17 18 void Start() 19 { 20 } 21 22 void Update() 23 { 24 if (script == null) 25 { 26 talkingflag = false; 27 } 28 29 else 30 { 31 talkingflag = script.TalkFlag; 32 } 33 34 if (talkingflag == true) 35 { 36 if (talkUIInstance == null) 37 { 38 talkUIInstance = GameObject.Instantiate(talkUIPrefab, Vector3.zero, Quaternion.identity, Parent) as GameObject; 39 } 40 } 41 else 42 { 43 if (talkUIInstance != null) 44 { 45 Destroy(talkUIInstance); 46 } 47 } 48 49 50 } 51}

もっといい方法があると思いますが、自分のやりたいことはとりあえずできるようにはなりました。
アドバイスくださったsakura_hanaさま、ありがとうございました。

投稿2019/02/12 10:14

kagiyama

総合スコア10

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問