- Home /
Question by
Polepole · Aug 11, 2020 at 10:16 AM ·
scripting probleminstantiatespawning problemszombie
Problems with instantiate
I'm trying to create a spawn for enemies and when they are instantiated, they've got the error NullReferenceException because some of their public components in the hierarchy are not being assigned like the Audio Source...
But these components that are not being assigned are all of them in bold in the inspector so I guess that's the problem. Anyone can help me fix that please?
Here's the code for instantiating enemies.
void Spawn() {
Vector3 SpawnPos = new Vector3(0, 0, 0);
SpawnPos = this.transform.position + Random.onUnitSphere * RongCreacio;
SpawnPos = new Vector3(SpawnPos.x, 0, SpawnPos.z);
GameObject z = Instantiate(zombie, SpawnPos, Quaternion.identity) as GameObject;
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613005239im_/https://answers.unity.com/themes/thub/images/avi.jpg)