/// <summary>
    /// Controls each interaction between colliders
    /// </summary>
    /// <param name="other"></param>
    void OnTriggerStay2D(Collider2D other)
    {
        //If colliding with the spikes, kills the player
        if (other.tag == "Spikes")
        {
            AudioSource.PlayClipAtPoint(spikeSound, transform.position);
            PlayerHealth playerHealth = gameObject.GetComponent <PlayerHealth>();
            playerHealth.damagePlayer(playerHealth.maxHealth);
        }

        // If colliding with a vessel, destroy it and add 1 point
        if (other.tag == "Vessel")
        {
            gm.points += 1;
            PlayerPrefs.SetInt("Score", gm.points);
            Instantiate(sparkle, transform.position, transform.rotation);
            AudioSource.PlayClipAtPoint(vesselPickUp, transform.position);
            Destroy(other.gameObject);
        }

        // If colliding with the finish door, loads the Finish scene
        if (other.tag == "Finish")
        {
            Instantiate(sparkle, transform.position, transform.rotation);
            AudioSource.PlayClipAtPoint(finishSound, transform.position);
            Destroy(gameObject, 0.25f);
            gm.changeScene(3);
        }
    }
Beispiel #2
0
 /// <summary>
 /// Kills the player and loads the Game Over scene
 /// </summary>
 public void kill()
 {
     Destroy(gameObject);
     gm.changeScene(2);
 }