実現したいこと
- DoTweenを使用したテキスト送りのプログラムの修正をしたい。
- DoTweenで送るテキストを外部からも設定できるようなプログラムを作りたい。
前提
unity2DでPlayerタグに触れたうえでsを入力するとtextを表示するプログラムを作っています。
textを1文字ずつ表示するプログラムを作っている時に表示されない問題が起こりました。
textを外部から設定する[SerializeField]を_text.DOText("流れるテキスト123456789", 2);の前に置いたときにエラーメッセージが出ました。
発生している問題・エラーメッセージ
以下のエラーメッセージがPlayerタグに触れたうえでsを入力すると出力されました。
DOTWEEN ► Tween startup failed (NULL target/property - System.String <DOText>b__0()): the tween will now be killed ► Object reference not set to an instance of an object UnityEngine.Debug:LogWarning (object) DG.Tweening.Core.Debugger:LogSafeModeCapturedError (object,DG.Tweening.Tween) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/Debugger.cs:61) DG.Tweening.Tweener:DoStartup<string, string, DG.Tweening.Plugins.Options.StringOptions> (DG.Tweening.Core.TweenerCore`3<string, string, DG.Tweening.Plugins.Options.StringOptions>) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tweener.cs:143) DG.Tweening.Core.TweenerCore`3<string, string, DG.Tweening.Plugins.Options.StringOptions>:Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenerCore.cs:250) DG.Tweening.Core.TweenManager:Update (DG.Tweening.Tween,single,single,bool) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:533) DG.Tweening.Core.TweenManager:Update (DG.Tweening.UpdateType,single,single) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:417) DG.Tweening.Core.DOTweenComponent:Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:75)
該当のソースコード
C#言語
1using UnityEngine; 2using DG.Tweening; 3using UnityEngine.UI; 4 5public class talk : MonoBehaviour 6{ 7 public GameObject dialogue; 8 public Text Text; 9 bool Talk = false; 10 private Text _text = default; 11 12 13 14 private void OnCollisionEnter2D(Collision2D other) 15 { 16 if (other.gameObject.CompareTag("Player")) 17 { 18 Talk = true; 19 20 } 21 } 22 23 private void OnCollisionExit2D(Collision2D other) 24 { 25 if (other.gameObject.CompareTag("Player")) 26 { 27 dialogue.SetActive(false); 28 Talk = false; 29 } 30 } 31 private void Update() 32 { 33 if (Input.GetKey("s")) 34 { 35 if (Talk == true) 36 { 37 [SerializeField] 38 _text.DOText("流れるテキスト123456789", 2); 39 dialogue.SetActive(true); 40 } 41 } 42 } 43}
試したこと
https://kan-kikuchi.hatenablog.com/entry/DoTween_DoText#google_vignette
を参考にしました。
まずは変数について学習されたほうがいいかもしれませんね

回答1件
あなたの回答
tips
プレビュー