尝试更改textmeshpro文本时出现Unity错误

时间:2019-03-09 22:27:31

标签: c# unity3d text

我想知道是否有人可以帮助我,我收到此错误:NullReferenceException: Object reference not set to an instance of an object PlayerStone.AdvanceMoveQueue () (at Assets/Scripts/PlayerStone.cs:197) PlayerStone.Update () (at Assets/Scripts/PlayerStone.cs:109) 我不确定为什么在我引用我的对象时会弹出此错误。我想知道是否有人可以帮助我解决这个问题,我尝试了一系列解决方案,您可以使用// //从我的代码中看到这些解决方案,但是尝试更改文本的方法均无效。我将附上我的剧本和一张照片。

Player Stone脚本的一部分

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

public class PlayerStone : MonoBehaviour
{
// Use this for initialization
  void Start()
  {
    theStateManager = GameObject.FindObjectOfType<StateManager>();
    EnableObj = GameObject.FindObjectOfType<EnableMenu>();
    EnableWinObj = GameObject.FindObjectOfType<enableWin>();
    EnableLoseObj = GameObject.FindObjectOfType<enableLose>();
    Player1Score = GameObject.FindObjectOfType<PlayerScore>();
    targetPosition = this.transform.position;
    TextControl TextControl = GameObject.FindObjectOfType<TextControl>();
    //TextControl.returnStone = returnStone;
    //scoreValue = GetComponent<TextMeshProUGUI>();


}
//public Transform scoreValue;
public Tile StartingTile;
public Tile CurrentTile { get; protected set; }

public int PlayerId;
public StoneStorage MyStoneStorage;

bool scoreMe = false;
bool ScoreDisplay = false;
public static int ScoreValue = 0;
public static int PlayerScore = 0;
public static int Player2Score = 0;

//public Transform scoreCount;

//public Transform score;
//public GameObject EndGameScreen;
//private TextMeshProUGUI textMesh;






StateManager theStateManager;
EnableMenu EnableObj;
enableWin EnableWinObj;
enableLose EnableLoseObj;
PlayerScore Player1Score;
void Update(){
   if (ScoreValue <= 6)
            {
                ScoreValue ++;

                Debug.Log("Player 1 Score = " + ScoreValue);
                if (ScoreValue >= 6)
                {
                    Debug.Log("You Win");
                    EnableWinObj.EndGameObj();
                    //Player1Score.GetPlayerScore();
                    //Wait();
                    ScoreDisplay = true;
                    if (ScoreDisplay == true)
                    {
                        //if (score == null)
                        //{
                        //    Debug.LogError("SomeVariable has not been assigned.", this);
                        //}

                        // textMesh.text = score.ToString();
                        //scoreValue.ToString();
                        //scoreValue.GetComponent<TMPro.TextMeshProUGUI>().text = "1";
                        //scoreValue.GetComponent<TMPro.TextMeshProUGUI>().text = ScoreValue.ToString();
                        Player1Score.GetPlayerScore();
                        ScoreDisplay = false;
                        Time.timeScale = 0f;
                    }




                }
            }

}

0 个答案:

没有答案