I have been trying to place this script on an invisible object to mark that as a checkpoint
当我尝试执行此操作时,它似乎并不想工作并且我不完全确定为什么,它一直告诉我 spawnPoint 未分配给任何东西,但这应该在 CheckPoint 脚本中发生。请帮忙
最佳答案
您在 GoToCheckpoint
脚本中的 spawnPoint
似乎没有链接到 Checkpoint
脚本的 spawnPoint
。除非您在检查器中分配了一些东西,否则返回该错误是正常的。
要从 GoToCheckpoint
脚本访问 Checkpoint
脚本的 spawnPoint
,您可以做一些简单的事情,将其更改为静态字段。
更改 Checkpoint
脚本的 spawnPoint
并删除不需要的其他脚本的 spawnPoint
。
public static Transform spawnPoint;
然后在 GoToCheckpoint
脚本中,您可以在更新函数中调用它
void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("returning to checkpoint");
tf.position = Checkpoint.spawnPoint.position;
}
}
关于c# - 我怎样才能创建一个激活的检查点系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43024128/