Example #1
0
    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.layer == 9 || other.gameObject.layer == 12) //Boundaries and Ground Layers
        {
            Destroy(gameObject);
        }
        if (other.gameObject.layer == 10) //Enemy Layer
        {
            //Deal Damage
            EnemyHealth enemyHealthScript = other.gameObject.GetComponent <EnemyHealth>();
            enemyHealthScript.health -= damage;

            //Knockback
            EnemyDetectionMovement EDM = other.gameObject.GetComponent <EnemyDetectionMovement>();
            EDM.Knockback(knockback, gameObject, true);

            //BloodParticles
            bloodsplatter.DoBloodSplatter(other.gameObject.transform);

            //Hurt Sound (has to be the second audio source in the enemy's inspector).
            AudioSource[] enemyHurtSound = other.gameObject.GetComponents <AudioSource>();
            enemyHurtSound[1].Play();

            //Destroy self (instantiated bullet)
            Destroy(gameObject);
        }
    }
Example #2
0
    //Used when the enemy leaves the melee trigger area or if the enemy is dead.
    void SetInfoToNull()
    {
        isWithinMeleeRange = false;

        enemy          = null;
        EH             = null;
        EDM            = null;
        enemyLocation  = null;
        enemyHurtSound = null;
    }
Example #3
0
    //Takes info from the enemy while it's within trigger range.
    void GetInfo(Collider other, bool reset = false)
    {
        if (!reset)
        {
            isWithinMeleeRange = true;

            enemy          = other.gameObject;
            EH             = enemy.GetComponent <EnemyHealth>();
            EDM            = enemy.GetComponent <EnemyDetectionMovement>();
            enemyLocation  = enemy.transform;
            enemyHurtSound = enemy.GetComponents <AudioSource>();
        }
        else
        {
            SetInfoToNull();
        }
    }
Example #4
0
    void Explode()
    {
        Instantiate(explosionEffect, transform.position, transform.rotation);
        model.SetActive(false);
        bombSizzle.Stop();

        Collider [] colliders = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider nearbyObject in colliders)
        {
            EnemyDetectionMovement EDM = nearbyObject.gameObject.GetComponent <EnemyDetectionMovement>();
            Rigidbody      rb          = nearbyObject.GetComponent <Rigidbody>();
            ImpactReceiver IR          = nearbyObject.GetComponent <ImpactReceiver>();

            if (rb != null) //Add explosion force to rigidbody objects
            {
                float distance = Vector3.Distance(transform.position, nearbyObject.transform.position);

                //If within a 4 range distance of the pipebomb
                if (distance <= 4)
                {
                    if (EDM != null)
                    {
                        StartCoroutine(EDM.ChangeIsKinematic());
                        EDM.isWithinDetectionRange = true;
                    }
                    rb.AddExplosionForce(force, transform.position, radius);
                }
                else
                {
                    if (EDM != null)
                    {
                        StartCoroutine(EDM.ChangeIsKinematic());
                        EDM.isWithinDetectionRange = true;
                    }
                    rb.AddExplosionForce((force / 1.5f), transform.position, radius);
                }
            }

            if (IR != null) //Add explosion force to CharacterController objects
            {
                Vector3 dir      = nearbyObject.transform.position - transform.position;
                float   distance = Vector3.Distance(transform.position, nearbyObject.transform.position);

                //If within a 4 range distance of the pipebomb
                if (distance <= 4)
                {
                    IR.AddImpact(dir, (force / 8));
                }
                else
                {
                    IR.AddImpact(dir, (force / 10));
                }
            }

            if (nearbyObject.tag == "Player") //If the object's tag is a player, deal some damage depending on the player's distance to the explosion.
            {
                DealExplosionDamage(nearbyObject);
            }
            if (nearbyObject.tag == "Enemy") //If the object's tag is an enemy, deal some damage depending on the enemy's distance to the explosion.
            {
                EnemyHealth enemyHealthScript = nearbyObject.GetComponent <EnemyHealth>();

                if (enemyHealthScript != null)
                {
                    DealExplosionDamage(nearbyObject, enemyHealthScript);
                }
            }
        }
    }
Example #5
0
 void Awake()
 {
     EDM = gameObject.GetComponent <EnemyDetectionMovement>();
 }
 void Awake()
 {
     SS  = GameObject.FindGameObjectWithTag("Player").GetComponent <SlotSelection>();
     EDM = gameObject.GetComponentInParent <EnemyDetectionMovement>();
 }