예제 #1
0
파일: HPPowerUp.cs 프로젝트: EetuHei/Group8
    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);
        }
    }
예제 #2
0
 // 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>();
 }
예제 #3
0
 // 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>();
 }