コード例 #1
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag(tagToDamage))
     {
         HealthService healthSrv = collision.gameObject.GetComponent <HealthService>();
         if (healthSrv)
         {
             healthSrv.DealDamage(damage);
         }
     }
 }
コード例 #2
0
    //public Text healthBar;
    private void OnCollisionEnter(Collision collision)
    {
        Instantiate(hitAnimation, transform.position, transform.rotation);

        //healthBar.text = (Int64.Parse(healthBar.text) - damage).ToString();

        if (collision.gameObject.CompareTag(tagToDamage))
        {
            HealthService healthSrv = collision.gameObject.GetComponent <HealthService>();
            if (healthSrv)
            {
                healthSrv.DealDamage(damage);
            }
        }
    }