在unity里我遇到一个问题报错但是好像可以运行,但是我害怕后面的代码会因此运行不起来,求帮忙看看
NullReferenceException: Object reference not set to an instance of an object(对象引用未设置为对象的实例)
DebugScreen.Update () (at Assets/Script/DebugScreen.cs:38)
脚本是这样的:
public class DebugScreen : MonoBehaviour
{
World world;
Text text;
float frameRate;
float timer;
int halfWorldSizeInVoxels;
int halfWorldSizeInChunks;
void Start()
{
world = GameObject.Find("World").GetComponent<World>();
text = GetComponent<Text>();
halfWorldSizeInVoxels = VoxelData.WorldSizeInVoxels / 2;
halfWorldSizeInChunks = VoxelData.WorldSizeInChunks / 2;
}
void Update()
{
string debugText = "b3agz' Code a Game Like Minecraft in Unity";
debugText += "\n";
debugText += frameRate + " fps";
debugText += "\n\n";
debugText += "XYZ: " + (Mathf.FloorToInt(world.player.transform.position.x) - halfWorldSizeInVoxels) + " / " + Mathf.FloorToInt(world.player.transform.position.y) + " / " + (Mathf.FloorToInt(world.player.transform.position.z) - halfWorldSizeInVoxels);
debugText += "\n";
debugText += "Chunk: " + (world.playerChunkCoord.x - halfWorldSizeInChunks) + " / " + (world.playerChunkCoord.z - halfWorldSizeInChunks);
text.text = debugText;
if (timer > 1f)
{
frameRate = (int)(1f / Time.unscaledDeltaTime);
timer = 0;
}
else
timer += Time.deltaTime;
}
}