我试图在单击按钮时实例化玩家前面的墙。我为此使用physics.checkbox,因为我想检查玩家前面是否已经有墙壁或gameObject。根据代码,“位置不可用”总是在控制台中打印,而忽略在产卵位置是否存在任何对撞机的事实。我不知道我是否使用正确。帮助。
public class WallBuilder : MonoBehaviour
{
public GameObject horizontal, vertical;
public void BuildWallButton()
{
Vector3 verticalWallPosition = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y + 3, this.transform.position.z+0.05f);
if (Physics.CheckBox(verticalWallPosition, vertical.GetComponent<Collider2D>().bounds.extents,Quaternion.identity))
{
Debug.Log("Available");
GameObject upWays = Instantiate(vertical, verticalWallPosition, Quaternion.identity);
}
else
{
Debug.Log(verticalWallPosition.y);
Debug.Log("Position not available");
}
//GameObject sideWays = Instantiate(horizontal, horizontalWallPosition);
}
}