Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //Move towards portal center if winning condition is met
        if (ifWin)
        {
            Destroy(myRigidbody);
            soundController.enabled = false;
            myAnimation.enabled     = false;
            transform.position      = Vector2.MoveTowards(transform.position, portal.transform.position, 2f * Time.deltaTime);

            if (transform.position == portal.transform.position)
            {
                int nextStage = stage.GetComponent <Stage_Info> ().GetNextStage();
                SceneManager.LoadScene(nextStage);
            }
        }
        else if (ifStunned)
        {
            //Trigger stun animation when stunned
            myAnimation.MakeStun();

            stunTimer -= Time.deltaTime;


            //Color goes back to normal after half of the stun time, otherwise being red
            if (stunTimer <= (timeOfStunned / 2f))
            {
                mySpriteRenderer.color = prevColor;
            }
            else
            {
                mySpriteRenderer.color = Color.red;
            }


            //Stop stun animation and quit stun state when timer's zero
            if (stunTimer <= 0)
            {
                myAnimation.StopStun();
                ifStunned = false;
            }
        }
        else if (!ifDead)            //Normal condition
        {
            myRigidbody.velocity = new Vector2(0, myRigidbody.velocity.y);

            PlayerMove();
            ShootProjectile();
            SwitchForm();
        }


        //Conditions for game over
        if (transform.position.y < (stage.GetComponent <Stage_Info>().GetDownBorder() - 2) || myBehavior.getHealth() <= 0)
        {
            ifDead = true;


            //Record failing state and the current stage to come back to
            Menu_Clear.ifFailed    = true;
            Menu_Clear.failedScene = stage.GetComponent <Stage_Info> ().nextStage - 1;


            //Player turns black when dying
            Color dyingColor = Color.Lerp(Color.black, mySpriteRenderer.color, dyingTimer);
            mySpriteRenderer.color  = dyingColor;
            eyeSpriteRenderer.color = dyingColor;
            dyingTimer -= Time.deltaTime / dyingTime;

            if (dyingTimer <= 0)
            {
                SceneManager.LoadScene("stageFail");
            }
        }
    }