Point scoring system not working Unity (visual studio C#)

  Uncategorised

my total_score variable is stored in the PLayerSpawner class. When an enemy dies it does not increase the score how it should. I would like to increase by 50 points but it doesn’t work. I’ve been trying solutions but can’t figure it out. This is in a different class called DamageByCollision class. any help / solutions would help!!!

void Update()
{

    if (invulnTimer > 0)
    {
        invulnTimer -= Time.deltaTime;

        if (invulnTimer <= 0)
        {
            gameObject.layer = correctLayer;
            if (spriteRend != null)
            {
                spriteRend.enabled = true;
            }
        }
        else
        {
            if (spriteRend != null)
            {
                spriteRend.enabled = !spriteRend.enabled;
            }
        }

    }

    if (health <= 0)
    {
        Die();
    }
}

void Die()
{
    Destroy(gameObject);
    if (gameObject == enemyPrefab)
    {
        PlayerSpawner.total_score = PlayerSpawner.total_score + 50f;
    }
}Lease help!!!!!


void Update()
{

    if (invulnTimer > 0)
    {
        invulnTimer -= Time.deltaTime;

        if (invulnTimer <= 0)
        {
            gameObject.layer = correctLayer;
            if (spriteRend != null)
            {
                spriteRend.enabled = true;
            }
        }
        else
        {
            if (spriteRend != null)
            {
                spriteRend.enabled = !spriteRend.enabled;
            }
        }

    }

    if (health <= 0)
    {
        Die();
    }
}

void Die()
{
    Destroy(gameObject);
    if (gameObject == enemyPrefab)
    {
        PlayerSpawner.total_score = PlayerSpawner.total_score + 50f;
    }
}

Source: Visual Studio Questions

LEAVE A COMMENT