My spawner is supposed to spawn prefabs because the prefabs go towards a target, but instead, it spawns clones of the prefab as a gameobject and the new gameobject doesn’t go towards the target. Is there a way to spawn prefabs instead of clone gameobjects?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class spawner : MonoBehaviour
{
public GameObject objectToSpawn;
public GameObject newobject;
// Use this for initialization
void Start()
{
InvokeRepeating("SpawnObject", 1f, 1f);
}
// Update is called once per frame
void SpawnObject()
{
float randomX = Random.Range(387, 120);
Vector3 randomLocation = new Vector3(randomX, 3, 455);
newobject = Instantiate(objectToSpawn, randomLocation, transform.rotation);
}
}