void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         //increase the damage here then remove the object.
         ProjDamage         = GetComponent <projectileDamage>();
         ProjDamage.damage += damageInc;
         Destroy(gameObject);
     }
 }
Example #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        projectileDamage P = col.GetComponent <projectileDamage> ();

        if (col.tag == "Instant Death")
        {
            health = 0;
        }
        else if (P != null && P.shooter != this.transform && invuln == false)
        {
            takeDamage(col.GetComponent <projectileDamage>().damage);
            if (health <= 0)
            {
                col.GetComponent <projectileDamage>().shooter.GetComponent <player>().kills += 1;
            }
        }
    }
Example #3
0
    void projectileDoesDamage(objectHealth target, GameObject projectile, Vector3 impactPoint, Vector3 impactNormal, Vector3 impactRelVelocity)
    {
//		Debug.Log ("projectile made contact with " + gameObject.tag);

        projectileDamage hit = projectile.GetComponent <projectileDamage> ();
        int selfSize         = target.getHealth();
        int hitDamage        = (int)(hit.getDamage());

//		Debug.Log ("projectile damage eoc:  " + hitDamage);

        if (selfSize > hitDamage)
        {
            int foodHealth;
//			Debug.Log ("hit object health1:  " + contacteeHealth.getHealth() + " hit damage: " + hitDamage);
            int newHealth = target.getHealth() - hitDamage;

            if (name == "Boss")
            {
                newHealth = target.getHealth() - (int)(hitDamage * impactDamageMultiplier);
            }

            target.instantiateHealth(newHealth);
//			Debug.Log ("hit object health2:  " + contacteeHealth.getHealth() + "new Health var:  " + newHealth);

            Destroy(projectile);
            int chunks = (int)(hitDamage / 5);
            // making boss not emit any food
            // making boss ANIMATE taking hit!!
            if (name == "Boss")
            {
                chunks = 0;
                Animator [] animArray     = target.GetComponentsInChildren <Animator> ();
                Animator    animActivator = animArray [0];
                animActivator.SetTrigger("takeDamage");

                audioSource = target.GetComponent <AudioSource> ();
                audioSource.PlayOneShot(hitSound, 1f);
            }


            if (target.CompareTag("food"))
            {
//				Debug.Log ("Projectile is trying to look shocked");
                Animator [] animArray     = target.GetComponentsInChildren <Animator> ();
                Animator    animActivator = animArray [0];
                animActivator.SetTrigger("takeDamage");

                audioSource = target.GetComponent <AudioSource> ();
                audioSource.PlayOneShot(takeDamageSound, .7f);
            }              //make food animate

            for (int i = 0; i < chunks; i++)
            {
                foodHealth = (int)(hitDamage / chunks) + 5;                 // adding fudge 5 points to spawn foods health

//				Vector3 startPoint = other.contacts [0].point;
                Vector3 testPoint     = impactPoint;
                Vector3 spawnPosition = impactPoint;

                GameObject food = foodTypes [Random.Range(0, foodTypes.Length)];

                while (impactPoint == spawnPosition)
                {
                    Vector2 randGen   = Random.insideUnitCircle * 2f;
                    Vector3 randPoint = new Vector3(randGen.x, 0, randGen.y);
                    testPoint += randPoint;
//					Debug.Log (testPoint);
                    bool test = testNewObjectPosition(food, testPoint, (food.transform.localScale.x / 2f));                       //assuming base size is 100 here

                    if (test)
                    {
                        spawnPosition = testPoint;
                    }
                }

                Quaternion spawnRotation = Random.rotation;

                GameObject newFood = (GameObject)Instantiate(food, spawnPosition, spawnRotation);
                newFood.GetComponent <objectHealth> ().instantiateHealth(foodHealth);

//				Vector3 direction = other.contacts [0].normal;
                Vector3 dirRandomizor = Random.insideUnitSphere * 2f;
                Vector3 velocityRB    = impactNormal + dirRandomizor + impactRelVelocity;

                Rigidbody foodRB = newFood.GetComponent <Rigidbody> ();
                foodRB.AddForce(-velocityRB * 8f);
            }
        }
        if (selfSize <= hitDamage)
        {
            Destroy(gameObject);
            Destroy(projectile);
        }
    }