- Home /
C# error help ( CS0023 Operator '--' cannot be applied to operand of type 'Stat'
Ive been using the help of multiple sources for my code to pile together a game, and its working somewhat well except for the fact that i cant get my player to take damage
public class PlayerHealth : MonoBehaviour
{
[SerializeField]
private Stat health;
private void Awake ()
{
health.Initialize();
}
void Update ()
{
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "blob_enemy")
{
health--;
if (health < 0)
health = 0;
coll.gameObject.GetComponent<PlayerHealth>().receiveDamage(10);
}
}
public void receiveDamage(float amount)
{
health -= amount;
if (health <= 0)
{
Destroy(gameObject);
}
}
}
i don't quite know what to do in this situation so some help would be appreciated, i'm using unity 5.6.
Answer by Buckslice · Dec 02, 2017 at 02:44 AM
It looks like Stat has the -= operator overloaded so you could instead just say health-=1 instead of health--. Or you could go overload the -- operator in the Stat class. C# operator overloading
Your answer
Follow this Question
Related Questions
health decrease only once and stop player movement 1 Answer
Scene not restarting after player death 2 Answers
How can i remove the player in an array? 1 Answer
I have an attack/take damage script how do I make the player die when health hits 0? 1 Answer
How can I lose health when my enemy collides with the player? 1 Answer