I can’t seem to find where and why is this error. It is displayed that the error is on line 33 and line 45(Scripts\EnemySpawner.cs(33,45): error CS1503: Argument 1: cannot convert from ‘method group’ to ‘float’). Any Idea how I can fix this and where is the issue?
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
[SerializeField] List<WaveConfigSO> waveConfigs;
[SerializeField] float timeBetweenWaves = 0f;
WaveConfigSO currentWave;
void Start()
{
StartCoroutine(SpawnEnemyWaves());
}
public WaveConfigSO GetCurrentWave()
{
return currentWave;
}
IEnumerator SpawnEnemyWaves()
{
foreach (WaveConfigSO wave in waveConfigs)
{
currentWave = wave;
for(int i = 0; i < currentWave.GetEnemyCount(); i++)
{
Instantiate(currentWave.GetEnemyPrefab(i),
currentWave.GetStartingWaypoint().position,
Quaternion.identity,
transform);
yield return new WaitForSeconds(currentWave.GetRandomSpawnTime);
}
}
yield return new WaitForSeconds(timeBetweenWaves);
}
}
I think that the error from 45 line could be somewhere here:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Wave Config", fileName = "New Wave Config")]
public class WaveConfigSO : ScriptableObject
{
[SerializeField] List<GameObject> enemyPrefabs;
[SerializeField] Transform pathPrefab;
[SerializeField] float moveSpeed = 5f;
[SerializeField] float timeBetweenEnemySpawns = 1f;
[SerializeField] float spawnTimeVariance = 0f;
[SerializeField] float minimumSpawnTime = 0.2f;
public int GetEnemyCount()
{
return enemyPrefabs.Count;
}
public GameObject GetEnemyPrefab(int index)
{
return enemyPrefabs[index];
}
public Transform GetStartingWaypoint()
{
return pathPrefab.GetChild(0);
}
public List<Transform> GetWaypoints()
{
List<Transform> waypoints = new List<Transform>();
foreach(Transform child in pathPrefab)
{
waypoints.Add(child);
}
return waypoints;
}
public float GetMoveSpeed()
{
return moveSpeed;
}
public float GetRandomSpawnTime()
{
float spawnTime = Random.Range(timeBetweenEnemySpawns - spawnTimeVariance,
timeBetweenEnemySpawns + spawnTimeVariance);
return Mathf.Clamp(spawnTime, minimumSpawnTime, float.MaxValue);
}
}