Beispiel #1
0
    // for objects the fish can move through, eg. a pond
    void OnTriggerEnter(Collider other)
    {
        if (respawning || wonLevel)
        {
            return;
        }

        if (other.tag == "Obstacle")            // hit an obstacle, respawn
        {
            StartCoroutine(Respawn(false));
        }
        if (other.tag == "Seagull")                     // respawn, but the seagull picks up the fish!!
        {
            StartCoroutine(TakenBySeagull(other.gameObject));
            StartCoroutine(Respawn(false));
        }
        if (other.tag == "Water")                       // update oxygen, but NOT respawn point
        {
            GetComponent <FishSound>().playEnterWaterSound();
            fishOxygen.EnterWater();
        }
        if (other.tag == "Pond")                        // update oxygen and respawn point
        {
            GetComponent <FishSound>().playEnterWaterSound();
            fishOxygen.EnterWater();

            // respawn point
            Vector3 pondPos = other.transform.position;
            float   yOffset = 2.0f;             // keep the fish out of any colliders beneath it
            fishMovement.respawnPosition = new Vector3(pondPos.x, pondPos.y + yOffset, pondPos.z);
        }
        if (other.tag == "Goal")                        // end of level
        {
            wonLevel = true;
            fishMovement.inControl = false;                     // disable jumping after beating the level
            GetComponent <FishSound>().playEnterWaterSound();
            fishOxygen.EnterWater();
            winScreen.SetActive(true);
            WinScreen winScreenScript = GameObject.Find("New Canvas").GetComponent <WinScreen>();
            winScreenScript.ShowTotalJump();
            winScreenScript.saveScore();
            winScreenScript.loadScore();
        }
    }