I have been having trouble exposing the Dynamic float in the inspector for the unity event:
For some reason it is just not coming up. I have googled it a lot and it seems to be a bug that has come and gone in several versions of unity.
But to keep pushing on the just did it in code:
In the Health.cs:
public delegate void OnTakeDamageDelegate(float damage);
public OnTakeDamageDelegate onTakeDamage;
then add to the TakeDamage method: onTakeDamage(damage);
This is my DamageTextSpawner.cs (bit different to the lecture and nothing is in the DamageText.cs):
using UnityEngine;
using UnityEngine.UI;
using RPG.Resources;
namespace RPG.UI.DamageText
{
public class DamageTextSpawner : MonoBehaviour
{
[SerializeField] GameObject damageTextPrefab;
private void OnEnable()
{
GetComponentInParent<Health>().onTakeDamage += Spawn;
}
private void OnDisable()
{
GetComponentInParent<Health>().onTakeDamage -= Spawn;
}
public void Spawn(float damageText)
{
GameObject spawnedText = Instantiate(damageTextPrefab, transform.position, Quaternion.identity);
Text text = spawnedText.GetComponentInChildren<Text>();
text.text = damageText.ToString(); //if decimal places are an issue use string.format
Destroy(spawnedText, 1f);
}
}
}
I hope my work around helps. But I would like to know if there is a solution to the Dynamic float not appearing.