Exemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D hit)
    {
        // Checks if the collider is valid
        if (!hit)
        {
            return;
        }

        // Checks if the object can be picked up
        if (hit.CompareTag("PickUp"))
        {
            // Pickup the object
            _source.PlayOneShot(pickUpSound);
            var item = hit.GetComponent <PickUp>();
            _inventoryManager.Add(item);
            Destroy(hit.gameObject);
        }
        else if (hit.CompareTag("Heart"))
        {
            // Pickup heart to regain lives
            if (TotalLives > _remainingLives)
            {
                _source.PlayOneShot(HeartSound);
                _remainingLives++;
                _playerHeartDisplay.OnChangeHeart(TotalLives, _remainingLives);

                // Destroys the game object
                Destroy(hit.gameObject);
            }
        }
    }
Exemplo n.º 2
0
 public void HealPlayer(MedPack medPack, AudioClip clip)
 {
     if (lives != maxLives)
     {
         audioSource.PlayOneShot(clip);
         lives++;
         Instantiate(medPack.pickUpEffect, transform.position, transform.rotation);
         Destroy(medPack.gameObject);
         display.OnChangeHeart(maxLives, lives);
     }
 }
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        oxygen  = max0xygen;
        lives   = maxLives;
        display = GetComponent <PlayerHeartDisplay>();
        display.OnChangeHeart(maxLives, lives);
        display.OnChangeOxygen((int)oxygen);
        oxygenCounter = liveLossTime;

        invisibilityCounter = 0;
        flashCounter        = flashLength;

        audioSource = GetComponent <AudioSource>();
        controller  = GetComponent <PlayerController>();
    }