Ejemplo n.º 1
0
    // Attempts to damage the passed GameObject whilst managing the piercing state of the bullet
    void DamageMob(GameObject mob, int damage, bool incrementPierceCounter = false)
    {
        if (Network.isServer && mob)
        {
            if (!m_isPiercing || !m_pastHits.Contains(mob))
            {
                //Debug.Log("Attempting to damage mob: " + mob.name);
                HealthScript health = mob.GetComponent <HealthScript>();

                if (health)
                {
                    health.DamageMob(damage, firer, gameObject);

                    m_isPiercing = m_isPiercing && health.GetCurrShield() == 0 ? true : false;

                    if (incrementPierceCounter)
                    {
                        m_pastHits.Add(mob);
                        networkView.RPC("ApplyPierceModifiers", RPCMode.All);
                    }
                }

                else
                {
                    Debug.LogError("Unable to find HealthScript on: " + mob.name);
                }
            }
        }
    }
Ejemplo n.º 2
0
    // Damage the mob, apply impact force and sync its position over the network if it's an asteroid
    void DamageHit(RaycastHit hit)
    {
        // Colliders may be part of a composite collider so we must use Collider.attachedRigidbody to get the HealthScript component
        Rigidbody mob = hit.collider.attachedRigidbody;

        if (hit.collider.tag != "Shield")
        {
            // Push the enemy away from the force of the beam
            mob.AddForceAtPosition(transform.up * m_impactForce * Time.deltaTime, hit.point);
        }

        // Only the host should cause damage
        if (Network.isServer)
        {
            if (m_overflow > 1f)
            {
                int damage = (int)m_overflow;
                m_overflow -= damage;

                if (hit.collider.gameObject.layer == Layers.enemySupportShield)
                {
                    EnemySupportShieldScript script = hit.collider.gameObject.GetComponent <EnemySupportShieldScript>();
                    if (script)
                    {
                        script.DamageShield(damage);
                        script.BeginShaderCoroutine(hit.point);
                    }
                }

                else
                {
                    HealthScript health = mob.GetComponent <HealthScript>();
                    if (health)
                    {
                        health.DamageMob(damage, firer, gameObject);
                    }

                    else
                    {
                        Debug.LogError("Can't find HealthScript on " + mob.name);
                    }
                }
            }
        }
    }