void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Bullet") { Debug.Log(collision.gameObject.layer); if (collision.gameObject.layer != 8) { Debug.Log("Bullet Hit"); bulletMachanics projectileScript = collision.GetComponent <bulletMachanics>(); float damageOccured = projectileScript.damage; //Debug.Log(projectileScript.layer); currentHealth -= damageOccured; Destroy(collision.gameObject); healthBar.SetHealth(currentHealth); if (currentHealth <= 0) { Debug.Log("ded"); Destroy(gameObject); healthBar.disableBar(); } } } if (collision.name == "BossBegin") { transform.localEulerAngles = new Vector3(0f, 0f, 0f); rb.velocity = -transform.right * travelSpeed; Debug.Log("bossbeginblah"); } if (collision.name == "BossEnd") { transform.localEulerAngles = new Vector3(0f, 180f, 0f); rb.velocity = transform.right * travelSpeed; Debug.Log("bossendblah"); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Ground") { //Debug.Log("Grounded"); grounded = true; playerAnimations.SetBool("exitJump", true); } if (collision.tag == "Finish") { Debug.Log("finished"); end.EndGame(true); } if (collision.tag == "Respawn") { currentRespawnLocation = collision.transform; } if (collision.tag == "deathTrap") { Invoke("respawnPlayer", respawnDelay); playerLives--; } if (collision.tag == "Enemy") { getHitByenemy(defaultHealth); } if (collision.tag == "Bullet") { if (collision.gameObject.layer != 9) { bulletMachanics projectileScript = collision.GetComponent <bulletMachanics>(); float damageOccured = projectileScript.damage; Destroy(collision.gameObject); getHitByenemy(damageOccured); } } // might want to smooth these transitions }
// Update is called once per frame void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Bullet") { if (collision.gameObject.layer == 9) { bulletMachanics projectileScript = collision.GetComponent <bulletMachanics>(); float damageOccured = projectileScript.damage; health -= damageOccured; Debug.Log("Bullet Hit" + health); Destroy(collision.gameObject); if (health <= 0) { playerProfile.getKill(); Destroy(gameObject); } } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Bullet") { if (collision.gameObject.layer == 9) { bulletMachanics projectileScript = collision.GetComponent <bulletMachanics>(); float damageOccured = projectileScript.damage; health -= damageOccured; healthStatus.SetHealth(health); Debug.Log("Bullet Hit" + health); Destroy(collision.gameObject); if (health <= 0) { Destroy(gameObject); endfight.bossDefeated(); healthStatus.disableBar(); } } } }