namespace BarthaSzabolcs.Tutorial_SpriteFlash.Example
{
public class SimpleFlashExample : MonoBehaviour
{
[SerializeField] Health health;
[SerializeField] private SimpleFlash flashEffect;
[SerializeField] private KeyCode flashKey;
[SerializeField] public int m_health = 12;
private void Update()
{
if(health != m_health)
if (Input.GetKeyDown(flashKey))
{
flashEffect.Flash();
}
}
}
}```
#I want to get health variable from Health script and check if it is changed
1 messages · Page 1 of 1 (latest)
But I get this error Assets\SimpleFlashExample.cs(15,16): error CS0019: Operator '!=' cannot be applied to operands of type 'Health' and 'int'
m_health is an integer
health is a Health object
what are you trying to do here?
If health's value changed I want to make flashEffect.Flash(); happen
does Health have an integer field that stores your current health?
okay, then you'll just want to use that field
instead of trying to compare the Health component itself to the integer
How can I do it I can only put the script there
if you have a reference to Health, you can access any of its public fields
Health health = // get a Health, somehow
health.mana += 5;
health.experience *= 2;
if (health.health != lastHealthValue)
{
lastHealthValue = health.health;
DoFlash();
}
bro thank you so much for your help 🙏