void OnCollisionEnter(Collision coll) { if (coll.transform.tag == "Zombie") { DestroyableObject ZAI = coll.gameObject.GetComponent <DestroyableObject>(); if (ZAI.check(_word)) //if the words match up then we have hit our target //Do damage to this enemy { ZAI.hit(_weapon.getHitPower(), _weapon.getStunChance()); //Debug.Log ("Checking for splash damage position.x:" + transform.position.x + " position.y:" + transform.position.y); //Do splash damage GameObject [] allZombies = GameObject.FindGameObjectsWithTag("Zombie"); foreach (GameObject go in allZombies) { if (Vector2.Distance(go.transform.position, transform.position) < _range) { //Debug.Log ("Splashing Object:" + go.name); go.GetComponent <DestroyableObject>().splash(_splashDamage, _speedModifier, _knockback); } } } else if (_weapon.Penetrating) { ZAI.hit(_weapon.getHitPower(), _weapon.getStunChance()); } } if (!_weapon.Penetrating) { Destroy(gameObject); } }
/// <summary> /// Checks for kills. If the space bar is pressed check all zombies to see if any of them die /// </summary> private void checkForKills() { GameObject [] allZombies; allZombies = GameObject.FindGameObjectsWithTag("Zombie"); //get a list of all the zombies bool hit = false; //if this is false after checking all the zombies then we didn't get a single hit. If this happens //reset the combo to 1 if (allZombies.Length == 0) { try{ upgrades.resetCombo(); } catch { upgrades = GameObject.FindGameObjectWithTag("Upgrades").GetComponent <Upgrades>(); upgrades.resetCombo(); } return; } foreach (GameObject z in allZombies) { DestroyableObject ZAI = z.GetComponent <DestroyableObject>(); if (ZAI != null && ZAI.check(currentString)) //if it's a hit { Debug.Log("attempting to load projectile"); GameObject go_projectile = (GameObject)Instantiate(Resources.Load("Projectile")); go_projectile.transform.position = transform.position; go_projectile.GetComponent <Projectile>().setStats(z.transform, currentString, cw); //ZAI.hit(cw.getHitPower(),cw.getStunChance()); //Hit the zombie, causes the zombie to take damage, and be subject to other effects such as stun time hit = true; } } if (hit == false) //we didn't get a single hit, reset the combo { try{ upgrades.resetCombo(); } catch { upgrades = GameObject.FindGameObjectWithTag("Upgrades").GetComponent <Upgrades>(); upgrades.resetCombo(); } } }