【发布时间】:2021-07-03 13:23:49
【问题描述】:
我最近从本教程 https://youtu.be/YHSanceczXY 开始在 Unity 中制作 Pong 游戏,但其中一个代码不起作用
enter code here
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Goal : MonoBehaviour
{
public bool isPlayer1Goal;
private void OnTriggerEnter2D(Collider collision)
{
if (collision.gameObject.CompareTag("Ball"))
{
if (!isPlayer1Goal)
{
Debug.Log("Player 2 Scored...");
GameObject.Find("GameManager").GetComponent<GameManager>().Player2Scored;
}
else
{
Debug.Log("Player 1 Scored...");
GameObject.Find("GameManager").GetComponent<GameManager>().Player1Scored;
}
}
}
}
【问题讨论】:
-
程序语句必须做某事,即具有明显的副作用。检索
Player2Scored和Player1Scored属性值不会做任何事情,它只是获取那些然后立即丢弃的值。如果这些不是属性,那么您可能忘记了 调用 方法所需的名称后面的括号。查看重复项。