示例#1
0
    //Update is called once per frame
    void Update()
    {
        //Menu stuff.

        if (inSettings)
        {
            float hor  = Input.GetAxis(hmove);
            float vert = Input.GetAxis(vmove);

            if (hor <= 0.8f && hor >= -0.8f && vert <= 0.8f && vert >= -0.8f)
            {
                zeroAllTimers();
            }
            else
            {
                if (hor > 0.8f && rightTimer <= 0)
                {
                    rightTimer = rightTimer == -10 ? fastTimer : normalTimer;
                    gs.MenuSelectionRight();
                }
                if (rightTimer > 0)
                {
                    rightTimer -= Time.deltaTime;
                    if (rightTimer < 0)
                    {
                        rightTimer = -10;
                    }
                }
                if (hor < -0.8f && leftTimer <= 0)
                {
                    leftTimer = leftTimer == -10 ? fastTimer : normalTimer;
                    gs.MenuSelectionLeft();
                }
                if (leftTimer > 0)
                {
                    leftTimer -= Time.deltaTime;
                    if (leftTimer < 0)
                    {
                        leftTimer = -10;
                    }
                }
                if (vert > 0.8f && upTimer <= 0)
                {
                    upTimer = upTimer == -10 ? fastTimer : normalTimer;
                    gs.MenuSelectionUp();
                }

                if (upTimer > 0)
                {
                    upTimer -= Time.deltaTime;
                    if (upTimer < 0)
                    {
                        upTimer = -10;
                    }
                }
                if (vert < -0.8f && downTimer <= 0)
                {
                    downTimer = downTimer == -10 ? fastTimer : normalTimer;
                    gs.MenuSelectionDown();
                }

                if (downTimer > 0)
                {
                    downTimer -= Time.deltaTime;
                    if (downTimer < 0)
                    {
                        downTimer = -10;
                    }
                }
            }

            if (Input.GetButton(aButton) && !lastABut)
            {
                lastABut = true;
                gs.aPressed();
                inSettings = gs.show;
            }
            if (!Input.GetButton(aButton))
            {
                lastABut = false;
            }

            if (Input.GetButton(pause) && !lastPause)
            {
                lastPause = true;
                gs.toggleVisible();
                inSettings = false;
            }
            if (!Input.GetButton(pause))
            {
                lastPause = false;
            }
        }
        else if (gs == null || !gs.show)
        {
            if (GameManager.gameIsStarted)
            {
                if (GameManager.getPlayer(characterNumber))
                {
                    activeAiming.renderer.material = GameManager.getPlayer(characterNumber).GetComponent <MeshRenderer>().material;
                }

                checkInGameMenu();

                if (!GameManager.gameSet.show && !GameManager.isPaused)
                {
                    Utility u   = (Utility)(GetComponentInParent <Character>().util);
                    float   hor = Input.GetAxis(hmove);
                    //Debug.Log ("Wall left: " + IsWallLeft() + " , " + "Wall right: " + IsWallRight() + " , " + "jumping : " + isJumping);

                    float ang = hor > 0 ? 90 : hor == 0 ? lastAng : 270;
                    transform.rotation = Quaternion.Euler(new Vector3(0, ang, 0));
                    lastAng            = ang;

                    if ((!(u is Dash) || u.countdown <= 0) && !isWallJumping)
                    {
                        float wd = wallDir(0.01f);
                        if (((hor > 0 && wd < 0) || (hor < 0 && wd > 0)))
                        {
                            hor = 0;
                        }
                        rigidbody.velocity = (new Vector3(maxSpeed * hor, rigidbody.velocity.y, 0));

                        /*
                         * if (Mathf.Abs(hor) > 0.2f && wallDir(0.01f) != 0 && Mathf.Sign(wallDir(0.01f)) != Mathf.Sign(hor))
                         * {
                         * dropTimer = dropTime;
                         * }
                         */
                    }

                    /*
                     * if (Mathf.Abs(rigidbody.velocity.x) > maxSpeed) {
                     *  rigidbody.velocity = new Vector3(maxSpeed * Mathf.Sign (rigidbody.velocity.x), rigidbody.velocity.y, 0);
                     *          }
                     */
                    transform.position = new Vector3(transform.position.x, transform.position.y, 0);

                    Vector2 aim     = new Vector2(Input.GetAxis(haim) * hAimMod, Input.GetAxis(vaim) * vAimMod);
                    float   trigger = Input.GetAxis(firetrigger);
                    if (!GetComponent <Character>().isDead)
                    {
                        if ((aim.sqrMagnitude > 0.2f || GetComponent <CharacterProjectile>().p is Fireblast) && !fired && trigger > 0.5f)
                        {
                            fired = true;
                            //Debug.Log("Player Fire " + characterNumber);
                            GetComponentInParent <CharacterProjectile>().p.bullet.GetComponent <Magic>().owningChar = gameObject;
                            GetComponent <CharacterProjectile>().p.Fire(aim);
                        }
                    }
                    if (dropTimer > 0)
                    {
                        dropTimer -= Time.deltaTime;
                    }

                    //if (trigger >= -0.5) {
                    fired = false;
                    // }

                    int tcount = 0;
                    //Utility calls.
                    if (Input.GetAxis(utilTrigger) >= 0.5f)
                    {
                        if (u.countdown <= 0)
                        {
                            //Debug.Log ("Trigger thing" + tcount++);

                            //Debug.Log ("Activate thing.");
                            u.Activate();
                        }
                    }

                    if (aim.sqrMagnitude > 0.2f)
                    {
                        activeAiming.transform.position = transform.position + new Vector3(aim.normalized.x, aim.normalized.y, 0) * 0.7f;
                    }
                    else
                    {
                        activeAiming.transform.position = new Vector3(-1000, -1000, -1000);
                    }

                    if ((Input.GetAxis(vmove) < -0.5f))
                    {
                        dropTimer           = 0;
                        rigidbody.velocity += Physics.gravity * Time.deltaTime * 3;
                    }

                    if ((!isJumping) && IsGrounded(0.01f) && (Input.GetAxis(vmove) > 0.5))
                    {
                        //Debug.Log(characterNumber);
                        isJumping          = true;
                        rigidbody.velocity = new Vector3(rigidbody.velocity.x, jumpPower, 0.0f);
                    }

                    /*
                     * if (dropTimer > 0 && IsOnWall(0.01f))
                     * {
                     * rigidbody.velocity = new Vector3(rigidbody.velocity.x, 0, rigidbody.velocity.z);
                     * rigidbody.useGravity = false;
                     *
                     * } else
                     * {
                     * rigidbody.useGravity = true;
                     * }
                     */
                    /*
                     * if ((dropTimer > 0 && IsOnWall(0.01f) && !IsGrounded(0.01f) && (Input.GetAxis(vmove) > 0.7) && Mathf.Abs(Input.GetAxis(hmove)) < Input.GetAxis(vmove)))
                     * {
                     * int wallJumpDirection = wallDir(0.01f);
                     *
                     * rigidbody.velocity = new Vector3(jumpPower * wallJumpDirection * wallJumpMod, jumpPower, 0);
                     *
                     * if (wallJumpDirection != 0)
                     * {
                     *  isWallJumping = true;
                     *  transform.position += new Vector3(wallJumpDirection / 3, 0, 0);
                     * }
                     * }
                     */
                    if (rigidbody.velocity.y > jumpPower)
                    {
                        rigidbody.velocity = new Vector3(rigidbody.velocity.x, jumpPower, rigidbody.velocity.z);
                    }

                    if (rigidbody.velocity.y < -terminalVelocity)
                    {
                        rigidbody.velocity = new Vector3(rigidbody.velocity.x, -terminalVelocity, rigidbody.velocity.z);
                    }

                    bool grounded = IsGrounded(0.01f);
                    if (!isJumping && !grounded)
                    {
                        isJumping = true;
                    }
                    if (grounded)
                    {
                        isJumping = false;
                    }
                    //isJumping = true;
                }

                ///Pausing.
                if (Input.GetButton(pause))
                {
                    //GameManager.Pause(characterNumber);
                    if (!lastPause)
                    {
                        GameManager.Pause(characterNumber);

                        if (GameObject.FindObjectOfType <MenuSystem>())
                        {
                            if (!gs.show || inSettings)
                            {
                                gs.toggleVisible();
                                inSettings = gs.show;
                            }
                        }
                    }

                    lastPause = true;
                }
                else
                {
                    lastPause = false;
                }

                //Door code.
                if (Input.GetButton(xButton) && !lastX)
                {
                    GetComponent <Character>().CheckForDoor();
                    lastX = true;
                }
                if (!Input.GetButton(xButton))
                {
                    lastX = false;
                }
            }
        }
    }