ok, so far I managed to get rid of the errors, I did not get the sound to play when I want it to.
If I leave the tick on “play on awake” it plays when the enemy is spawned, if I untick, it doesn’t play at all. My health script with changes:
public class Health : MonoBehaviour
{
[SerializeField] float health = 100f;
[SerializeField] GameObject deathVFX = default;
[SerializeField] AudioSource deathSound = default;
//AudioSource deathSound; //- this should be an array which didn't work either
public void DealDamage(float damage)
{
health -= damage;
if (health <= 0)
{
TriggerDeathVFX();
PlayDeathSound();
Destroy(gameObject);
}
}
private void TriggerDeathVFX()
{
if(!deathVFX)
{
return;
}
GameObject deathVFXObject = Instantiate(deathVFX, transform.position, transform.rotation);
Destroy(deathVFXObject, 1f);
}
private void PlayDeathSound()
{
Debug.Log("Am I being called1?");
if (!deathSound)
{
return;
}
deathSound.volume = PlayerPrefsController.GetSFXVolume();
deathSound.Play();
Debug.Log("Am I being called2?");
}
}
my two debug.log’s are being called.
Somehow, I cannot shake off the feeling that I am approaching this the wrong way…anyways, I will continue this tomorrow…