예제 #1
0
    /***************************************************************/



    /********************* PRIVATE UTILITIES ***********************/
    private void RecoveryCache()
    {
        controller = GetComponent <CharacterController>();
        trans      = GetComponent <Transform> ();
        vitality   = GetComponent <VitalityComponent> ();
        cam        = Camera.main;
    }
예제 #2
0
    private void RecoveryCache()
    {
        agent    = GetComponent <NavMeshAgent> ();
        vitality = GetComponent <VitalityComponent> ();
        anim     = GetComponent <Animator> ();
        trans    = GetComponent <Transform> ();

        vitality.onDeath.AddListener(Death);
    }
예제 #3
0
    private void OnCollisionEnter(Collision other)
    {
        VitalityComponent vitality = other.gameObject.GetComponent <VitalityComponent> ();

        if (vitality != null)
        {
            vitality.TakeDamage(damage, other.contacts[0].point);
        }

        if (damageRadius > 0.001f)
        {
            int amount = Physics.OverlapSphereNonAlloc(this.trans.position, damageRadius, nonAlloc, damageMask);
            for (int i = 0; i < amount; i++)
            {
                VitalityComponent vit = nonAlloc [i].gameObject.GetComponent <VitalityComponent> ();
                if (vit && vit.tag != "Player" && vit != vitality)
                {
                    vit.TakeDamage(
                        damage * Vector3.Distance(this.trans.position, vit.transform.position) / damageRadius,
                        vit.transform.position
                        );
                }
            }
        }

        if (impactClip != null)
        {
            AudioSource.PlayClipAtPoint(impactClip, Vector3.zero, impactClipVolume);
        }

        if (explosionEffectPrefab != null)
        {
            ParticleManager.GetInstance().Show(explosionEffectPrefab.name, this.trans.position);
        }

        collisionAmount++;
        if (ammunition != null && (resistance <= collisionAmount || vitality == null))
        {
            ammunition.Recycle(this);
        }
    }