Problem with the damage the enemy does to the player

Mariano

New member
Hello community:
I am designing the enemies and within the script that goes into the enemy are these lines that refer to the damage done to the player.
The problem is that within Unity it works perfectly, but when I run it on the cell phone the player is not damaged.
What will be happening?
Are those damage script lines fine?
Damage occurs when the attack animation ends with EndAttack

Code:
public void EndAttack()

    {
        float dist = Vector3.Distance(Player.transform.position, this.transform.position);

        if (dist < meleeAtackRange)
        {
            Player.SendMessage("Damage", meleeDamage, SendMessageOptions.DontRequireReceiver);
            
            if (audioSource != null && SoundMelee != null)
                {
                audioSource.pitch = Time.timeScale;
                audioSource.PlayOneShot(SoundMelee);
                }
                //audioSource.PlayOneShot(SoundMelee);
            
        }

    }

¡Salud!
 

Justin

Administrator
Staff member
While I don't know if this would cause it, SendMessage is slow so you should call Damage directly:

 

Mariano

New member
While I don't know if this would cause it, SendMessage is slow so you should call Damage directly:


Thank you. I changed it to the new lines of code.

Code:
public int Damage = 1;

Code:
{
            var health = Player.GetComponent<Health>();
            if (health != null)
            {
                health.Damage(Damage); // Inflict damage on the character.
            }
}

But it's still the same. In Unity it does the damage but in Android it does not. I will continue researching because I don't know what may be happening.
Regards!
 
Top