- Home /
,Getting a Spawner Manager Script to reference a Spawner
Okay, so, I have coded a Spawner class with code that houses two prefabs to spawn at a certain speed based on whether or not a 0 or 1 gets inputed. I also have a separate SpawnManager class that chooses which spawner to spawn from and which prefab to spawn. The problem is that I have no idea how to get the SpawnManager to reference a Spawner in order to trigger it.
How would I accomplish getting my Manager code to reference a spawner in order to trigger it? Getting my code to reference other code has been a constant struggle for me, and would really like to understand this as it is my big major hurdle that I need to get over in order to get into indie gamedev.
Please, add the code of Spawner and Spawn$$anonymous$$anager to your question.
Answer by axellolledoering · Nov 07, 2020 at 09:06 AM
@royalfrost737 You should be able to Just reference the spawner class like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
private Spawner spawner;
// Here we access the prefabs in the Spawner class. In this case we instantiate it at the SpawnManager's position.
private void Update()
{
GameObject newSpawnedPrefab = Instantiate(spawner.prefab1, transform.position, Quaternion.identity);
}
}
I haven't tested it, but it should work. Let me know if it did