예제 #1
0
파일: Bullet.cs 프로젝트: S00197638/CA2
    void ApplyDamageToHealth(GameObject collidedObject)
    {
        HealthComponent health = collidedObject.GetComponent <HealthComponent>();

        if (health != null)
        {
            health.ApplyDamage(Damage);
        }
    }
예제 #2
0
    public static void DealDamage(GameObject DamagedObject, int Damage)
    {
        HealthComponent health = DamagedObject.GetComponent <HealthComponent>();

        if (health)
        {
            health.ApplyDamage(Damage);
        }
    }
예제 #3
0
    public void ApplyDamageToHealth(GameObject otherObject)
    {
        HealthComponent health = otherObject.GetComponent <HealthComponent>();

        if (health != null)
        {
            health.ApplyDamage(damage);
        }
    }
    //// NO UPDATE
    //private void Update()
    //{

    //}

    public void TriggerAttack()
    {
        if ((Time.time - lastAttackTime) < AttackCooldownTime)
        {
            return;
        }

        Ray ray = new Ray
        {
            origin    = FirePoint.position,
            direction = FirePoint.forward,
        };

        if (Physics.Raycast(ray, out RaycastHit raycastHit, Range, HitMask))
        {
            HealthComponent hitObject = raycastHit.collider.transform.root.GetComponent <HealthComponent>();
            //HealthComponent hitObject = raycastHit.collider.GetComponentInParent<HealthComponent>(); // can also do this
            if (hitObject != null)
            {
                Debug.DrawLine(ray.origin, raycastHit.point, Color.red, 0.5f);
                hitObject.ApplyDamage(Damage);
            }
        }
예제 #5
0
 protected void ApplyDamage(HealthComponent healthComponent)
 {
     healthComponent.ApplyDamage(DamagePerHit);
 }