Esempio n. 1
0
    void ApplyDamageToHealth(GameObject collidedObject)
    {
        HealthComponent health = collidedObject.GetComponent <HealthComponent>();

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

        if (health)
        {
            health.ApplyDamage(Damage);
        }
    }
Esempio n. 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);
            }
        }
Esempio n. 5
0
 protected void ApplyDamage(HealthComponent healthComponent)
 {
     healthComponent.ApplyDamage(DamagePerHit);
 }