Beispiel #1
0
    void Update()
    {
        //check enemies
        if (FindObjectsOfType <PlayerController>().Length < 2)
        {
            endTimer -= Time.deltaTime;
            if (endTimer <= 0.0f)
            {
                SceneManager.LoadScene("Main Menu");
            }
        }

        if (arbitaryHealth <= 0 && !(stat == status.death || stat == status.deathAnim))
        {
            takeDamage(0);
        }

        GetComponent <SpriteRenderer>().color = playerColor;
        m_attack.SetColor(playerColor);
        //Vector2 temp = GetComponent<SpriteRenderer>().bounds.size;
        //GetComponent<Collider2D>().bounds.size.Set(temp.x, temp.y, 0);
        leftWall   = onLeftWall();
        rightWall  = onRightWall();
        isOnGround = onGround();
        bool isDashing = invincibility.pollIsDodging();

        if (isDashing)
        {
            if (stat != status.dashing)
            {
                anim.Play("Dodging", 0, 1);
                animNeedsFinish = getAnimationTime("Dodging");
                stat            = status.dashing;
            }
        }
        else
        {
            if (stat == status.dashing)
            {
                stat = status.stationary;
            }
        }

        if (!isOnGround && (stat == status.slidingOnWall || stat == status.wallJump || stat == status.standingJump || stat == status.tickling) && (animNeedsFinish <= 0))
        {
            stat = status.falling;
        }

        if (animNeedsFinish > 0)
        {
            animNeedsFinish -= Time.deltaTime;
        }
        else
        {
            if (!isOnGround)
            {
                if (stat != status.death && stat != status.deathAnim)
                {
                    if (leftWall || rightWall)
                    {
                        stat = status.slidingOnWall;
                    }
                    else
                    {
                        stat = status.falling;
                    }
                }
            }
        }

        if (stat == status.slidingOnWall)
        {
            //activate sliding anim
            anim.Play("wallToRightWallSlide", 0);
            //anim.SetInteger("State", 5);
            stat = status.slidingOnWall;
        }
        else if (stat == status.falling)
        {
            //activate falling anim
            anim.Play("Falling", 0);
            //anim.SetInteger("State", 3);
            stat = status.falling;
        }
        else if (stat == status.death || stat == status.deathAnim)
        {
            anim.Play("death", 0);
        }

        //handle death positioning
        if (stat == status.death)
        {
            if (isOnGround)
            {
                GetComponent <Rigidbody2D> ().velocity    = Vector2.zero;
                GetComponent <Rigidbody2D> ().isKinematic = true;
                GetComponent <BoxCollider2D> ().isTrigger = true;
                transform.position -= new Vector3(0, 0.6f, 0);
                Vector3 localScale = ghostChild.transform.localScale;
                if (!facingRight)
                {
                    ghostChild.transform.position = new Vector3(transform.position.x + 0.9f, ghostChild.transform.position.y, transform.position.z);
                    XChild.transform.position     = new Vector3(transform.position.x - 0.9f, ghostChild.transform.position.y, transform.position.z);
                    localScale.x = Mathf.Abs(ghostChild.transform.localScale.x);
                }
                else
                {
                    localScale.x = ghostChild.transform.localScale.x;
                    XChild.transform.position     = new Vector3(transform.position.x + 0.9f, ghostChild.transform.position.y, transform.position.z);
                    ghostChild.transform.position = new Vector3(transform.position.x - 0.9f, ghostChild.transform.position.y, transform.position.z);
                }
                ghostChild.transform.localScale = localScale;
                ghostChild.SetActive(true);
                ghostChild.GetComponent <ghostAnimator> ().animEnum = ghostAnim.appear;
                stat = status.deathAnim;
            }
        }
        else if (stat != status.death && stat != status.deathAnim)
        {
            XChild.transform.position = new Vector3(transform.position.x, transform.position.y + 1.25f, transform.position.z);
        }

        if (isOnGround)
        {
            if (GetComponent <Rigidbody2D> ().velocity.y <= 0)
            {
                canDoubleJump = true;
                if (GetComponent <Rigidbody2D> ().velocity != Vector2.zero)
                {
                    if (!horizontal)
                    {
                        GetComponent <Rigidbody2D> ().velocity = Vector3.Lerp(GetComponent <Rigidbody2D> ().velocity, Vector2.zero, Time.deltaTime * slowDownSpeed);
                    }
                }
            }
            else
            {
                isOnGround = false;
            }
        }

        if (horizontal == false && isOnGround && !isDashing && (stat != status.death && stat != status.deathAnim) && stat != status.tickling)
        {
            //idle
            if (Mathf.Abs(GetComponent <Rigidbody2D> ().velocity.x) < 0.2f || stat == status.falling)
            {
                anim.Play("Idle", 0);
                //anim.SetInteger("State", 0);
                stat = status.stationary;
            }
        }

        //draw health ui
        if (ontopOf)
        {
            counterBox.SetActive(true);
            counter.SetActive(true);
            if (arbitaryHealth <= 0)
            {
                drawCounterBar(currentCount, respawnCount + (downMult * downs), counterDowned);
            }
            else
            {
                drawCounterBar(ontopOf.currentEnemyCount, ontopOf.enemyKillCount, counterOntop);
            }
        }
        else if (arbitaryHealth <= 0)
        {
            counterBox.SetActive(true);
            counter.SetActive(true);
            drawCounterBar(currentCount, respawnCount + (downMult * downs), counterDowned);
        }
        else
        {
            counterBox.SetActive(false);
            counter.SetActive(false);
        }

        horizontal      = false;
        keyPressDown    = false;
        canJumpVariable = false;

        if (stat == status.dodging || stat == status.slidingOnWall || stat == status.wallJump || stat == status.dashing || stat == status.death || stat == status.deathAnim || stat == status.tickling)
        {
            m_attack.SetAttackEnabled(false);
        }
        else
        {
            m_attack.SetAttackEnabled(true);
        }
    }