void OnColl2D(Collider2D coll, Collision2D collision = null) { //Debug.Log(coll.gameObject.tag); if (coll.gameObject.tag == "ball" && !m_dying && !m_player.isDead()) { ballFx ballScript = coll.gameObject.GetComponent <ballFx>(); float velocity = 0.0f; if (ballScript) { velocity = ballScript.m_smoothVelocity; } else { velocity = coll.rigidbody2D.velocity.magnitude; } if (velocity >= m_velocityOnBallToKillMe) { Vector2 pos = collision.contacts[0].point; rigidbody2D.fixedAngle = false; rigidbody2D.AddForceAtPosition(coll.rigidbody2D.velocity.normalized * velocity * 2000.0f, pos); if (m_hitSparks) { Instantiate(m_hitSparks, new Vector3(pos.x, pos.y, transform.position.z), Quaternion.identity); } if (!m_soundSource.isPlaying) { m_soundSource.PlayOneShot(m_hitSounds[Random.Range(0, m_hitSounds.Length)]); } if (m_player) { m_player.registerEnemyHurtbyBall(); } if (m_player) { m_comboOnHit = m_player.getBallCombo(); } GameObject gem; gem = Instantiate(m_deathGem, transform.position, Quaternion.identity) as GameObject; Gem gemscript = gem.GetComponent <Gem>(); gemscript.m_val = Mathf.Max(1, m_comboOnHit); kill(DeathCause.SMASHED, 0.5f); if (m_camShake) { m_camShake.Activate(0.5f, coll.rigidbody2D.velocity.normalized * velocity * 0.1f, new Vector2(velocity, velocity)); } } } else if (coll.gameObject.tag == "obstruction" && coll.rigidbody2D.velocity.y < -0.5f) { kill(DeathCause.CRUSH); } else if (coll.gameObject.tag == "firebomb") { //firebomb firebombScript = coll.gameObject.GetComponent<firebomb>(); //coll.gameObject.tag = "Untagged"; //firebombScript.explode(); } }
bool HandlePain(Collider2D p_other) { Debug.Log(p_other.gameObject.tag); if (p_other.gameObject.tag == "playerHurt" && m_invulnTick <= 0.0f && !m_dead) { m_hp--; if (m_hp <= 0) { StartCoroutine("kill"); } updateHealthUI(); Instantiate(m_hitFx, transform.position, Quaternion.identity); m_invulnTick = m_invulnTime; Vector3 hitDir = (transform.position - p_other.transform.position).normalized; rigidbody2D.AddForce(hitDir * 20000.0f); if (m_camShake) { m_camShake.Activate(1.0f, hitDir * 5.0f, new Vector2(10.0f, 20.0f)); } return(true); } return(false); }