Z
Z
zergon3212017-03-27 20:59:01
C++ / C#
zergon321, 2017-03-27 20:59:01

Why doesn't placing prefab instances with a script work?

There is an Enemy prefab, its instances are created by an empty object with the following component:

using UnityEngine;

public class Spawn : MonoBehaviour {

  [SerializeField] private GameObject EnemyPrefab; //need to be initialized in editor
  private GameObject spawned_enemy = null;
  
  void Update () {
    if (spawned_enemy == null) {
      spawned_enemy = (GameObject)Instantiate (EnemyPrefab);  
      spawned_enemy.transform.position = this.transform.position; 
      spawned_enemy.transform.Rotate(0, Random.Range(-90, 90), 0);
    }
  }
}

The spawned_enemy object does not appear in the scene.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Stupin, 2017-04-21
@Khan_RA

Try to watch this video
It seems that you are setting Instantiate incorrectly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question