Unity(C#)中无法实例化GameObject 敌人不生成问题求助
Unity实例化敌人Prefab无报错但不生成的问题及解决方法
问题描述
运行游戏时无报错,但敌人始终不生成——既看不到敌人,敌人也不会出现在层级面板中。已做以下尝试:
- 为
Instantiate方法添加位置和旋转参数,无效 - 确认在Inspector面板中已为脚本正确赋值敌人Prefab
使用的代码如下:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpawnEnemies : MonoBehaviour { public GameObject defaultenemy; public GameObject burstenemy; // Start is called before the first frame update void Start() { Instantiate(defaultenemy); } }
解决方法
问题已解决!原因是脚本未挂载到场景中的任何GameObject上,将脚本挂载到一个空GameObject后,敌人即可正常生成。
内容的提问来源于stack exchange,提问作者craig
相关产品推荐
相关产品推荐

