c# - How can I fix a warning saying something is missing in instantiate?
问题描述
In unity I had started making a game and had a similar problem to another post .How can I make it so that obstacles spawn based on how far the player has moved?. The answer on this had helped me very much and had used it on my code. I got another problem now as now I need to destroy my obstacles and I followed a similar concept to the code in the post. But now it says
The referenced script on this Behaviour (Game Object 'Triangles') is missing! UnityEngine.Object:Instantiate(GameObject) TriangleSpawner:Update() (at Assets/Scripts/TriangleSpawner.cs:22)
This is my code
if (Mathf.Abs(transform.position.x - Location) >= 15)
{
Location = transform.position.x;
GameObject newTriangle = Instantiate(Triangles);
newTriangle.name = Triangles.name;
newTriangle.transform.position = transform.position + new Vector3(Spacing, Random.Range(-2, 2), 0);
if (Mathf.Abs(newTriangle.transform.position.x - Player.transform.position.x) < -15)
{
Destroy(Triangles);
}
how can I fix this error?
解决方案
您正在破坏原始对象而不是克隆。尝试更改Destroy(Triangles);
为Destroy(newTriangle);
推荐阅读
- c# - ASP.NET Core 5 & Entity Framework:基于约定的导航问题
- sql - 使用 SSIS 在两个不同的服务器之间传输数据
- networking - 如何在 Rust 中重新组装 IP 分段的 UDP 数据包?
- laravel - 如何在开发服务器上更改基本 url 水平 laravel
- java - Student 类型不是有界参数的有效替代品
> 类型的 InsertionSort - python - Python Plotly:文本未出现在饼图的所有部分
- sql - 从客户订单表中查找最近的重复订单 - 慢速交叉应用
- reactjs - 如何添加缺少的模块“./lib/constants”?
- linux - 如何解决 linux 中 docker 卷挂载期间的文件处理问题?
- javascript - Npm run deploy 使用 GHpages 覆盖我试图推送到我的网站的内容