Hi,
It's probably best to start the conversation from C# code using DialogueManager.StartConversation() in this case. Here are three example ways you could do it:
1. In a TakeDamage() method:
Code: Select all
public void TakeDamage(int damage)
{
bool hpBecameLow = (hp > Threshold) && (hp - damage <= Threshold);
hp -= damage;
if (hpBecameLow) DialogueManager.StartConversation("Low HP Conversation");
}
Then cause damage to the player by calling the TakeDamage() method. I glossed over some values such as Threshold, but you should get the idea.
2. Or make HP a C# property:
Code: Select all
private int hp;
public int HP
{
get
{
return hp;
}
set
{
bool hpBecameLow = (hp > Threshold) && (value <= Threshold);
hp = value;
if (hpBecameLow) DialogueManager.StartConversation("Low HP Conversation");
}
}
3. Or a C# method property that invokes a C# event:
2. Or make HP a C# property:
Code: Select all
public System.Action<int, int> HPChanged = null;
private int hp;
public int HP
{
get
{
return hp;
}
set
{
int oldValue = hp;
hp = value;
HPChanged?.Invoke(oldValue, value);
}
}
...
void OnEnable() => HPChanged += OnHPChanged;
void OnDisable() => HPChanged -= OnHPChanged;
void OnHPChanged(int oldHP, int newHP)
{
bool hpBecameLow = (oldHP > Threshold) && (newHP <= Threshold);
if (hpBecameLow) DialogueManager.StartConversation("Low HP Conversation");
}