private void OnTriggerEnter2D(Collider2D collider) { if (collider.tag == "Player" && !picked) { //Getting the script that handles the HP GameObject player = collider.gameObject; RestartOnPlayerDeath playerScript = player.GetComponent <RestartOnPlayerDeath>(); picked = true; if (fullHP == true) { playerScript.currentHealth = playerScript.maxHealth; } else { //Checking if the health goes over max health when the power-up is picked up if (playerScript.maxHealth < (playerScript.currentHealth + HP_amount)) { playerScript.currentHealth = playerScript.maxHealth; } else { playerScript.currentHealth += HP_amount; } } playerScript.healthBar.SetHealth(playerScript.currentHealth); Destroy(gameObject); } }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody2D>(); audioSource = GetComponent <AudioSource>(); levelManager = FindObjectOfType <LevelManager>(); scoreManager = FindObjectOfType <ScoreManager>(); restartOnPlayerDeath = FindObjectOfType <RestartOnPlayerDeath>(); }
// Start is called before the first frame update void Start() { characterController = FindObjectOfType <CharacterController2D>(); playerDamageController = FindObjectOfType <RestartOnPlayerDeath>(); weaponController = FindObjectOfType <WeaponScript>(); normalJumpForce = characterController.m_JumpForce; normalFireRate = weaponController.fireRate; audioSource = gameObject.GetComponent <AudioSource>(); }