【发布时间】:2022-06-16 09:14:54
【问题描述】:
我已经在 Google 的首页上尝试了几乎所有解决方案,所以我想我会减少损失并找到我能想到的最佳来源。在这个脚本中,我试图让它在物体(球)接触其中一堵墙时调用一个函数。
if (Collider.gameObject.tag == "Player1Net"){
ScoreCounter Score;
Score = GameObject.FindGameObjectWithTag("Player1Net").GetComponent<ScoreCounter>();
Score.Player1Score();
}
对不起,如果这是一团糟,它基本上是我之前所有尝试修复它的合并。
这是我试图让它调用的脚本:
public class ScoreCounter : MonoBehaviour
{
public int Player1_Score;
public int Player2_Score;
public Text Player1ScoreText;
public Text Player2ScoreText;
public void Player1Score(){
Player1ScoreText.text = Player1_Score.ToString();
Player1_Score++;
SceneManager.LoadScene("GamePlay");
}
public void Player2Score(){
Player2ScoreText.text = Player2_Score.ToString();
Player2_Score++;
SceneManager.LoadScene("GamePlay");
}
我已经尝试了几乎所有我能想到的东西。有人可以帮我吗?非常感谢。
【问题讨论】:
-
试试这个:
public int Player1_Score = 0; public int Player2_Score = 0; public Text Player1ScoreText = new Text(); public Text Player2ScoreText = new Text();
标签: c# unity3d nullreferenceexception