実現したいこと
SendMessageを使った際のエラーを消すためのプログラムの修正内容について知りたいです。
前提
unity2Dでwarpタグに触れた際に別のプログラムのFadeメソッドを呼び出すプログラムを作っています。
発生している問題・エラーメッセージ
UnassignedReferenceException:The variable Canvas of WarpPoint has not been assigned. You probably need to assign the Canvas variable of the WarpPoint script in the inspector.
該当のソースコード
warpタグに触れた際に特定の座標へ移動し後者のプログラムのFadeメソッドを呼び出すプログラム
C#言語
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class WarpPoint : MonoBehaviour 6{ 7 public GameObject Canvas; 8 9 private Rigidbody2D rbody2D; 10 11 void Start() 12 { 13 rbody2D = GetComponent<Rigidbody2D>(); 14 } 15 private void OnTriggerEnter2D(Collider2D collider) 16 { 17 if (collider.gameObject.tag == "warp") 18 { 19 20 21 transform.position = new Vector3(-9.5f, 25.0f, 0.0f); 22 23 24 Canvas.SendMessage("Fade"); 25 } 26 27 } 28}
前者のプログラムによってFadeメソッドが呼び出されたときにPanelの透明度を徐々に上げていくプログラム
C#言語
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using UnityEngine.SceneManagement; 6 7public class Fadeout : MonoBehaviour 8{ 9 10 11 public GameObject Panelfade; 12 13 Image fadealpha; 14 15 private float alpha; 16 17 private bool fadeout; 18 19 public int SceneNo; 20 21 22 void Start() 23 { 24 fadealpha = Panelfade.GetComponent<Image>(); 25 alpha = fadealpha.color.a; 26 fadeout = false; 27 28 } 29 30 31 void Update() 32 { 33 if (fadeout == true) 34 { 35 alpha += 0.01f; 36 fadealpha.color = new Color(0, 0, 0, alpha); 37 if (alpha >= 1) 38 { 39 fadeout = false; 40 } 41 } 42 } 43 public void Fade() 44 { 45 fadeout = true; 46 } 47}
試した事
前者のプログラムの座標を変更するプログラムは
https://teratail.com/questions/1ci5p1jocxowa6#reply-7foej9keofed9x
を流用しました。
後者のプログラムのフェードアウトが行われるプログラムは
https://note.com/mi919/n/n96d2427d523c
を流用しました。
他のプログラムのメソッドを呼び出す方法は
https://ekulabo.com/send-messages-sample
を参考にしました。
回答1件
あなたの回答
tips
プレビュー