// Collision detection void OnTriggerEnter2D(Collider2D collision) { damageController dc = collision.gameObject.GetComponent <damageController>(); //local collision counter for enemy; natCol is initialized at 1 if (collision.tag == "Enemy") { natCol++; } // If it hits the player if (collision.tag == "Player") { // Does damage dc.doDamage(3, "none", originalPos, 0f); // Self Destructs Destroy(this.gameObject); } else if (collision.tag == "Wall" || collision.tag == "PowerBlock") { //spawn particles Destroy(this.gameObject); } //there's going to be a collision when the projectile is initialized; given this, each projectile //will have an odd-numbered number of collisions; damage will register at that point if (collision.gameObject.tag == "Enemy" && natCol % 2 != 0) { dc.doDamage(3, "none", originalPos, 0f); Destroy(this.gameObject); // collision.gameObject.GetComponent<turretController>().genTurret = true; } }
// Collision detection private void OnCollisionEnter2D(Collision2D collision) { // If it collided with the player if (collision.gameObject == player) { // Does damage damageController dc = collision.gameObject.GetComponent <damageController>(); dc.doDamage(3, "none", transform.position, 1.5f); } }
private void OnTriggerStay2D(Collider2D collision) { // If it's triggered by the player or an enemy if (collision.CompareTag("Player") || collision.CompareTag("Enemy")) { // Deals falling damage if the target can't fly. damageController dc = collision.gameObject.GetComponent <damageController>(); if (!dc.getFlying()) { dc.doDamage(0, "fall", transform.position, -1.5f); } } }
// Collision detection void OnTriggerEnter2D(Collider2D collision) { // If it hits an enemy if (collision.tag == "Enemy") { // Does damage damageController dc = collision.gameObject.GetComponent <damageController>(); int damage = 2; float knockback = 0.5f; dc.doDamage(damage, "none", originalPos, knockback); // Self Destructs Destroy(this.gameObject); } else if (collision.tag == "Wall" || collision.tag == "PowerBlock") { //spawn particle effect Destroy(this.gameObject); } }
// Collision detection void OnTriggerEnter2D(Collider2D collision) { // If it collides with the enemy if (collision.CompareTag("Enemy") && canSwing == false) { // Does full damage if (fullPower) { damageController dc = collision.gameObject.GetComponent <damageController>(); dc.doDamage(4, "none", player.transform.position, 0.5f); } // Does decreased damage else { damageController dc = collision.gameObject.GetComponent <damageController>(); dc.doDamage(1, "none", player.transform.position, 0f); } } }