c# - 我怎样才能创建一个激活的检查点系统

标签 c# unity3d

I have been trying to place this script on an invisible object to mark that as a checkpoint

And with this script i am trying to use the return key to go back to the previously touched 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/

相关文章:

c# - 将数据表转换为私有(private) List<List<string>>?

c# - 在 C# 中使用 Mongodb $in 过滤器

c# - 如何存储和序列化列表以避免长字符串

c# - Unity:带有PlayScheduled()的准确节拍器不起作用

c# - 识字 LINQ-to-XML : Best practice to deserialize attribute/value to structured variable/value pairs

c# - WinForms:为什么在显示文件夹浏览器对话框时出现 InvalidCastException?

c# - 如何在struct中初始化char数组

c# - Visual Studio 2013 和 Resharper 中的自动命名空间

c# - 如何修改 Bresenham 的线算法以保持顺序?

unity3d - 统一设置 Watson 开发人员 : credentials