Reputation: 29
click to see the image im trying to increment the variable "res" but somehow it get increment only one time while the destroy() working fine
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("enemy") )
{
res++;
Destroy(gameObject);
Debug.Log(res);
}
}
need help and thank you .
Upvotes: 1
Views: 58
Reputation: 336
One way to fix it is adding a static
in front of the variable for example from
public string name;
to
public static string name;
static
turns any variable into a variable that all instances of the class can use and that is the same for all instances. It works as "global" variable.
Upvotes: 1