public void Update()
 {
     consoleLog.transform.parent.GetComponent <RectTransform>().sizeDelta = new Vector2(consoleLog.transform.parent.GetComponent <RectTransform>().sizeDelta.x, CommandBackend.consoleSize);
     if (consoleLog.text != CommandBackend.consoleLog)
     {
         consoleLog.transform.parent.parent.parent.GetComponent <ScrollRect>().normalizedPosition = new Vector2(0, 0);
     }
     consoleLog.text = CommandBackend.consoleLog;
     if (Input.GetButtonDown("Submit"))
     {
         if (!CommandBackend.currentlyActive)
         {
             consoleWindow.gameObject.SetActive(true);
             CommandBackend.currentlyActive = true;
         }
         else if (!CommandBackend.executing && consoleInput.text != "")
         {
             string   command = consoleInput.text.Split(' ')[0];
             int      i       = consoleInput.text.IndexOf(" ") + 1;
             string[] args;
             if (i == 0) //repeats the original command ???
             {
                 args = new string[0];
             }
             else
             {
                 args = consoleInput.text.Substring(i).Split(' ');
             }
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             CommandBackend.PrintOutput("] " + consoleInput.text);
             consoleInput.text = "";
             CommandBackend.HandleConCommand(command, args);
         }
         consoleInput.Select();
         consoleInput.ActivateInputField();
     }
     else if (Input.GetButtonDown("Pause"))
     {
         consoleWindow.gameObject.SetActive(false);
         CommandBackend.currentlyActive = false;
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (CommandBackend.currentlyActive)
        {
            return;
        }
        if (Input.GetButtonDown("Pause"))
        {
            CommandBackend.HandleConCommand("quit");
        }
        if (Input.GetButton("Fire1") && !cooldown && !WeaponGUI.menuActive)
        {
            lookScript.activeWeapon.Fire();
            StartCoroutine(WeaponCooldown());
        }
        // If player is moving up, ignore collisions between player and platforms
        if (characterController.velocity.y > 0)
        {
            Physics.IgnoreLayerCollision(9, 10, true);
        }
        //else the collision will not be ignored
        else
        {
            Physics.IgnoreLayerCollision(9, 10, false);
        }
        //personality
        switch (personality)
        {
        default:     //assume personality is first one by default
            playerSprite.color = Color.green;
            break;

        case Personality.Dos:
            playerSprite.color = Color.magenta;
            break;
        }
        //If we hit something above us AND we are moving up, reverse vertical movement
        if ((characterController.collisionFlags & CollisionFlags.Above) != 0)
        {
            if (playerVelocity.y > 0)
            {
                playerVelocity.y = 0;
            }
        }
        //player states
        if (Input.GetAxis("Horizontal") != 0 && playerVelocity.y >= -0.5f && playerVelocity.y < -0f)
        {
            state = PlayerState.Walk;
        }
        else if (!groundedPlayer && playerVelocity.y > 0.5f)
        {
            state = PlayerState.Jumping;
        }
        else if (Input.GetAxis("Horizontal") != 0 && playerVelocity.y <= -0.5f && !groundedPlayer)
        {
            state = PlayerState.AirWalk;
        }
        else if (Input.GetAxis("Horizontal") == 0 && playerVelocity.y <= -0.5f && !groundedPlayer)
        {
            state = PlayerState.Falling;
        }
        else if (playerVelocity.y >= -0.5f && playerVelocity.y < -0f)
        {
            state = PlayerState.Idle;
        }
        //movement
        if (health > 0 && !flying)
        {
            groundedPlayer = characterController.isGrounded;
            if (groundedPlayer)
            {
                playerVelocity.y = 0f;
            }

            Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
            characterController.Move(move * Time.deltaTime * playerSpeed);

            /*if (transform.position.z != zPosition)
             * {
             *  //enter the tidal zone-style smooth z positioning v
             *  move.z = (zPosition - transform.position.z);
             * }*/
            if (Input.GetButton("Jump") && groundedPlayer)
            {
                playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
            }
            playerVelocity.y += gravityValue * Time.deltaTime;
            characterController.Move(playerVelocity * Time.deltaTime);
            transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
        }
        else if (flying)
        {
            Vector3 movingTo = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
            if (noClip)
            {
                transform.position = new Vector3(transform.position.x + Input.GetAxis("Horizontal"), transform.position.y + Input.GetAxis("Vertical"));
            }
            else
            {
                characterController.Move(movingTo * Time.deltaTime * playerSpeed);
            }
        }
        //mouse look vvv
        //Get the Screen positions of the object
        Vector2 positionOnScreen = Camera.main.WorldToViewportPoint(lookScript.transform.position);

        //Get the Screen position of the mouse
        Vector2 mouseOnScreen = (Vector2)Camera.main.ScreenToViewportPoint(Input.mousePosition);

        //Get the angle between the points
        float angle = AngleBetweenTwoPoints(positionOnScreen, mouseOnScreen);

        //this locked the position when you look down so you can't do a shot under yourself, got annoying v

        /*if(angle > 25f && angle < 90f)
         *  angle = 25f;
         * else if(angle < 150f && angle > 90f)
         *  angle = 150f;*/
        //anim
        if (angle > 10f && angle < 90f)
        {
            direction = PlayerDirection.LeftDown;
        }
        else if (angle >= -15f && angle < 10f)
        {
            direction = PlayerDirection.LeftForward;
        }
        else if (angle > -90f && angle < -15f)
        {
            direction = PlayerDirection.LeftUp;
        }
        else if (angle >= -150f && angle < -90f)
        {
            direction = PlayerDirection.RightUp;
        }
        else if (angle > -180f && angle < -150f)
        {
            direction = PlayerDirection.RightForward;
        }
        else if (angle < 180f && angle > 90f)
        {
            direction = PlayerDirection.RightDown;
        }
        //Ta Daaa
        lookScript.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle));

        switch (direction)
        {
        case PlayerDirection.RightForward:
            lookScript.weaponSprite.flipY = true;
            break;

        case PlayerDirection.RightUp:
            lookScript.weaponSprite.flipY = true;
            break;

        case PlayerDirection.RightDown:
            lookScript.weaponSprite.flipY = true;
            break;

        default:
            lookScript.weaponSprite.flipY = false;
            break;
        }
    }