Answer the question
In order to leave comments, you need to log in
C#(Unity) - Why is int not incremented?
There are two classes, the first class is the parent class, and it has an int, and a method in which this int is incremented. In the second class, the method is called, and according to the plan, int should increase, but nothing comes out. Here is the code:
public int Triger = 0;
public void GetDamage ()
{
hp--;
if (hp == 0) //P.S. Объект не один, поэтому должно работать не один раз
{
Trigger++;
Destroy (gameObject);
}
}
//Второй класс
void OnTriggerEnter2D(Collider2D collider)
{
Unit unit = collider.GetComponent<Unit>();
if (unit && unit is Character)
{
if (Mathf.Abs(unit.transform.position.x - transform.position.x) < 0.3F) GetDamage();
else unit.ReceiveDamage();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question