コード例 #1
0
    private void ApplyDamage(StatHolder enemyStatHolder)
    {
        Health health = enemyStatHolder.FindPropertyByName("Health") as Health;

        enemyStatHolder.DisplayDamage(enemyStatHolder.gameObject.GetComponent <SpriteRenderer>());
        if (health != null)
        {
            if (health.Hurt != null)
            {
                audioSource.clip = health.Hurt;
                audioSource.Play();
            }

            health.ApplyDamage((Attack)statHolder.FindPropertyByName("Attack"));
        }
    }
コード例 #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (tags.Contains(collision.tag))
        {
            StatHolder statHolder = collision.GetComponent <StatHolder>();
            statHolder.DisplayDamage(collision.GetComponent <SpriteRenderer>());
            Health health = statHolder.FindPropertyByName("Health") as Health;

            if (health != null)
            {
                if (health.Hurt != null)
                {
                    audioSource.clip = health.Hurt;
                    audioSource.Play();
                }

                health.ApplyDamage(attack);
            }
        }
    }