前提・実現したいこと
シーン上のTextMeshProUGUIのオブジェクトを取得し、スクリプトから操作したいです。
(ポイントが加算されるごとに何ポイントか表示するなど...)
発生している問題・エラーメッセージ
下記のように書いたところ、このような二つのエラーが発生しています。
TextMeshProUGUI' does not contain a definition for 'Find' EndLayoutGroup: BeginLayoutGroup must be called first. UnityEngine.GUILayout:EndVertical () TMPro.TMP_PackageResourceImporter:OnGUI () (at Library/PackageCache/com.unity.textmeshpro@2.1.6/Scripts/Runtime/TMP_PackageResourceImporter.cs:76) TMPro.TMP_PackageResourceImporterWindow:OnGUI () (at Library/PackageCache/com.unity.textmeshpro@2.1.6/Scripts/Runtime/TMP_PackageResourceImporter.cs:215) UnityEngine.GUIUtility:ProcessEvent (int,intptr) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)
該当のソースコード
C#
1this.pointText = TextMeshProUGUI.Find("pointText");
全文はこのようになっています。
C#
1public class JudgeController : MonoBehaviour 2{ 3 4 private TextMeshProUGUI pointText; 5 public int point = 0; 6 private GameObject round; 7 private GameObject falseRound; 8 private GameObject gameOverText; 9 private GameObject OutImage1; 10 private GameObject OutImage2; 11 private GameObject OutImage3; 12 private Image image_component1; 13 private Image image_component2; 14 private Image image_component3; 15 16 public bool isGameOver = false; 17 public bool isGameClear = false; 18 public int missCount = 0; 19 20 private float mouseClickedTime = 0.0f; 21 22 public RoundGenerator roundGenerator; 23 public GameManager gameManager; 24 // Start is called before the first frame update 25 void Start() 26 { 27 this.pointText = TextMeshProUGUI.Find("pointText"); 28 this.falseRound = GameObject.Find("falseRound"); 29 this.gameOverText = GameObject.Find("gameOverText"); 30 this.OutImage1 = GameObject.Find("outImage1"); 31 this.OutImage2 = GameObject.Find("outImage2"); 32 this.OutImage3 = GameObject.Find("outImage3"); 33 34 this.image_component1 = OutImage1.GetComponent<Image>(); 35 this.image_component2 = OutImage2.GetComponent<Image>(); 36 this.image_component3 = OutImage3.GetComponent<Image>(); 37 38 image_component1.enabled = false; 39 image_component2.enabled = false; 40 image_component3.enabled = false; 41 } 42 43 // Update is called once per frame 44 void Update() 45 { 46 if(this.isGameOver == true){ 47 this.gameOverText.GetComponent<Text>().text = "ゲームオーバー"; 48 Invoke("GameOver",2.0f); 49 } 50 if(Input.GetMouseButtonDown(0)){ 51 mouseClickedTime = 0.1f; 52 } 53 if(mouseClickedTime > 0.0f){ 54 mouseClickedTime -= Time.deltaTime; 55 } 56 } 57 58 public void GameOver(){ 59 SceneManager.LoadScene("GameOverScene"); 60 } 61 62 public void MissCount(){ 63 if(missCount == 1){ 64 image_component1.enabled = true; 65 } 66 if(missCount == 2){ 67 image_component2.enabled = true; 68 } 69 if(missCount == 3){ 70 image_component3.enabled = true; 71 } 72 } 73 74 void OnTriggerStay2D(Collider2D other){ 75 if(other.gameObject.tag == "roundTag"){ 76 if(mouseClickedTime > 0.0f){ 77 this.point += 10; 78 this.pointText.GetComponent<Text>().text = this.point + "ポイント"; 79 Destroy(other.gameObject); 80 gameManager.finishRoundNumber += 1; 81 if(gameManager.finishRoundNumber == gameManager.maxRound){ 82 this.isGameClear = true; 83 } 84 } 85 }else if(other.gameObject.tag == "falseRoundTag"){ 86 if(mouseClickedTime > 0.0f){ 87 missCount += 1; 88 if(missCount == 3){ 89 this.isGameOver = true; 90 } 91 MissCount(); 92 Destroy(other.gameObject); 93 gameManager.finishRoundNumber += 1; 94 if(gameManager.finishRoundNumber == gameManager.maxRound){ 95 this.isGameClear = true; 96 } 97 } 98 } 99 } 100} 101
ご教授いただけますと幸いです。よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/08/23 06:06