c# - C#/Unity 中的延迟
问题描述
我想在 Unity 中做一个延迟,因为对象不应该立即被销毁。
注意:yield WaitForSeconds (0.25);
对我不起作用。它给出了许多错误,例如
; 预期的
即使我有一个。
这是源代码:
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Enemy")
{
//Here 2 Seconds Delay
Destroy(gameObject);
}
}
}
解决方案
Destroy() 方法的第二个参数可以在销毁之前将浮点数作为延迟,例如:
Destroy(gameObject, 2F);
推荐阅读
- r - 数据框中的数据格式
- bazel - bazel 会截断或附加到现有的 build_event_json_file 吗?
- build - 错误:expo buidl 时请求失败,状态码为 400
- gecko - Gecko:如何获取请求(而不是响应)标头?
- angular - 在 Angular 中访问隐藏的标头参数
- r - 在R中计算碳随时间的半衰期
- c# - 如何使用特殊字符:在 Url C# webApi 中
- c# - Http Post 永远不会从 Twilio 返回,但会执行 Twilio 操作
- django - 403 错误“未提供身份验证凭据”在 Safari 中,但在 Chrome、Edge、Firefox 等中没有。[Django + Next.js]
- sql - 堆栈查询结果为一个查询结果,因此行的顺序取决于哪个部分返回哪个结果