Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.y < killDepth) //player has fallen in the water. it is now dead.
        {
            if (state != STATE.DEAD)
            {
                respawnAudioSource.GetComponent <AudioSource>().PlayDelayed(1f);
                DeathSound.GetComponent <AudioSource>().Play();
            }
            //print("You're dead!");
            state = STATE.DEAD;
        }
        else if (transform.position.y < respawnHeight)
        {
            state = STATE.ALIVE;
        }

        if (extraFall)
        {
            rb.AddForce(
                -rb.velocity.x,
                -1 * extraGravityMultiplier * (IsIn(-6.6f, 18, rb.position.x) || rb.position.z > 1.19f?1:0),
                -rb.velocity.z * (IsIn(-14.9f, 0.4f, rb.position.z) || rb.position.z > 1.19f ? 1 : 0),
                ForceMode.Acceleration);

            print("extra fall being added");
        }



        if (state == STATE.DEAD) //when the player is dead, do respawn counter
        {
            gameHandler.RespawnTime(playerNumber, respawnCounter - Time.time);


            if (respawnCounter == -1)
            {
                respawnCounter = Time.time + respawnTime;
            }
            else if (Time.time >= respawnCounter)
            {
                Respawn();
            }
        }
        else if (state == STATE.ALIVE)
        {
            //rotate via user input
            if (transform.position.y < 1.5f)
            {
                transform.Rotate(0, rotateSpeed * Input.GetAxis(inputHorizontalAxis) * Time.deltaTime, 0);
            }
        }
    }