I have a WaveSpawner script that spawns an array of waves. Each wave has an array of enemies.
This works perfectly when i assign everything in the inspector.
What I’m trying to do is populate the arrays in the waveSpawner Gameobject with a scriptable object that is referenced on another object.
The object StopPoint is what holds the scriptable object.
public class WaveSpawner : MonoBehaviour
{
[SerializeField] private Wave[] waveArray;
public GameObject currentStopPoint;
void Update()
{
if(currentStopPoint != null)
{
if (currentStopPoint.GetComponent<StopPoint>().isActive)
{
if (state == State.Idle)
{
//currentStopPoint.GetComponent<StopPoint>().wavesArray.CopyTo(waveArray, 3);
//System.Array.Copy(currentStopPoint.GetComponent<StopPoint>().wave, waveArray, 2);
//waveArray.Copy(currentStopPoint.GetComponent<StopPoint>().wave, waveArray);
WaveObject.Waves[] wavesArray = currentStopPoint.GetComponent<StopPoint>().wave.wavesArray;
//waveArray = wavesArray;
//waveArray.Copy(wavesArray, waveArray, 2);
//waveArray = System.Array.Copy(wavesArray, waveArray, 3);
//waveArray = waveArray.Copy(wavesArray, waveArray, wavesArray.Length);
waveArray = wavesArray.CopyTo(waveArray, wavesArray.Length);
waveArray = waveArray.Copy(wavesArray, waveArray, wavesArray.Length);
//waveArray = System.Array.Copy(currentStopPoint.GetComponent<StopPoint>().wave.wavesArray, waveArray, currentStopPoint.GetComponent<StopPoint>().wave.wavesArray.Length);
StartSpawn();
}
}
}
public void StartSpawn()
{
//wave.SpawnEnemies();
state = State.Active;
}
/// <summary>
///
/// </summary>
[System.Serializable]
public class Wave
{
[SerializeField] private Enemy[] enemiesArray;
[SerializeField] private float timer;
// public Transform spawnPoint;
public static int enemyCount;
}
Scriptable object
[CreateAssetMenu]
public class WaveObject : ScriptableObject
{
public Waves[] wavesArray;
[System.Serializable]
public class Waves
{
public Enemy[] enemiesArray;
public float timer;
// public Transform spawnPoint;
}