Hi,
In the tutorials, we are setting some values of the Enemies(maxtime, mintime and proj.speed) through the enemy.cs and I would like to be able to set them through the scriptable object that we create for the waves that we want to spawn.
I have tried to set some public variables and tried to call them from the enemy.cs which did not work. (I tried to use FindObjectOfType) and I tried to make methods of which return these values but I could not manage to call these methods and set their values on the matching values in the enemy. cs.
Enemy.cs:
Blockquote
[SerializeField] public float health = 100f;
[SerializeField] float shotCounter;
[SerializeField] float minTimeBetweenShots;
[SerializeField] float maxTimeBetweenShots;
[SerializeField] GameObject enemyProjectile;
[SerializeField] float projectileSpeed;
WaveConfig waveConfig;
[SerializeField] private WhiteFlash whiteFlash;
[SerializeField] GameObject powerUp;
PowerUpManager pUpMan_E;
PowerUp pUp_E;
[SerializeField] GameObject shL, shR;
[SerializeField] GameObject explosion;
public Transform firePosition2;
public Transform firePosition1;
// Start is called before the first frame update
void Start()
{
shotCounter = Random.Range(minTimeBetweenShots, maxTimeBetweenShots);
pUpMan_E = FindObjectOfType<PowerUpManager>();
pUp_E = FindObjectOfType<PowerUp>();
}
// Update is called once per frame
void Update()
{
CountDownAndShoot();
}
private void CountDownAndShoot()
{
shotCounter -= Time.deltaTime;
if (shotCounter <= 0f)
{
Fire();
shotCounter = Random.Range(minTimeBetweenShots, maxTimeBetweenShots);
}
}
WaveConfig.cs:
Blockquote[CreateAssetMenu(menuName = “Enemy Wave Config”)]
public class WaveConfig : ScriptableObject
{
[SerializeField] GameObject enemyPrefab;
[SerializeField] GameObject pathPrefab;
[SerializeField] float timeBetweenSpawns = 0.5f;
[SerializeField] float spawnRendomFactor = 0.3f;
[SerializeField] int numberOfEnemies = 5;
[SerializeField] float moveSpeed = 2f;
[SerializeField] public bool isMoveType1, isMoveType2;
public GameObject GetEnemyPrefab() {return enemyPrefab;}
public List<Transform> GetWaypoints()
{
var waveWaypoints = new List<Transform>();
foreach (Transform child in pathPrefab.transform)
{
waveWaypoints.Add(child);
}
return waveWaypoints;
}
public float GetTimeBetweenSpawns() { return timeBetweenSpawns; }
public float GetSpawnRendomFactor() { return spawnRendomFactor; }
public int GetNumberOfEnemies() { return numberOfEnemies; }
public float GetMoveSpeed() { return moveSpeed; }
}
How can I change these values(max-min_time,projectilespeed) through waveConfig scriptable object?
Any Ideas?Thanx in advance…Cheers=)