private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Enemy") { EnemyHealthScript s = collision.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); } }
private void OnTriggerEnter(Collider other) { if (other.tag != "Player" && harpoonFlying) { harpoonFlying = false; this.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); if (other.gameObject.tag == "ClamArmor") { //ClamShellScript s = other.gameObject.GetComponent<ClamShellScript>(); //s.OnHarpoonHit(); audioSource.clip = chitinImpactClip; audioSource.Play(); } if (other.gameObject.tag == "BarnacleArmor") { //BarnacleShellScript b = other.gameObject.GetComponent<BarnacleShellScript>(); //b.OnHarpoonHit(); audioSource.clip = chitinImpactClip; audioSource.Play(); } if (other.gameObject.tag == "Enemy") { EnemyHealthScript s = other.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); audioSource.clip = fleshImpactClip; audioSource.Play(); } if (other.gameObject.tag == "ClamCollider") { audioSource.clip = fleshImpactClip; audioSource.Play(); } if (other.gameObject.tag == "EnemyHarpoonable") { EnemyHealthScript s = other.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); audioSource.clip = fleshImpactClip; audioSource.Play(); } strikeJoint = gameObject.AddComponent <FixedJoint>(); if (other.attachedRigidbody) { strikeJoint.connectedBody = other.attachedRigidbody; } else { audioSource.clip = rockImpactClip; audioSource.Play(); stuckInTerrain = true; } } }
void OnCollisionEnter(Collision collision) { bool destroyThis = false; bool armorImpact = false; if (Random.Range(0, 5) != 0) { destroyThis = true; } if (collision.gameObject.tag == "Enemy") { EnemyHealthScript s = collision.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); destroyThis = true; } if (collision.gameObject.tag == "EnemyHarpoonable") { EnemyHealthScript s = collision.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); destroyThis = true; } Debug.Log(collision.gameObject.tag); if (collision.gameObject.CompareTag("BarnacleArmor") || collision.gameObject.CompareTag("ClamArmor")) { armorImpact = true; } if (destroyThis) { GameObject i = Instantiate(impactPrefab, this.transform.position, Quaternion.identity); if (armorImpact) { i.GetComponent <LaserImpactScript>().armorImpact = true; } Destroy(this.gameObject); } }
void OnCollisionEnter2D(Collision2D collision) { // Collision with enemy NewEnemyScript enemy = collision.gameObject.GetComponent <NewEnemyScript> (); if (enemy != null) { // Kill the enemy EnemyHealthScript enemyHealth = enemy.GetComponent <EnemyHealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp, 0); } // AKA deal as much damage as the enemy's health. // Deals 1 damage to to the player. HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1, 0); } } }
void OnCollisionEnter(Collision collision) { if (lifetime >= armingTime) { Instantiate(impactPrefab, this.transform.position, Quaternion.identity); Destroy(this.gameObject); Collider[] objectsWithinExplosion = Physics.OverlapSphere(transform.position, 30.0f); foreach (Collider c in objectsWithinExplosion) { if (c.gameObject.tag == "Enemy") { EnemyHealthScript s = c.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); } if (c.gameObject.tag == "EnemyHarpoonable") { EnemyHealthScript s = c.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); } } } }