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;
     }
 }
Пример #2
0
 void Start()
 {
     CommandBackend.AddConCommand("noclip", (string[] args) =>
     {
         noClip = !noClip;
         flying = noClip;
         CommandBackend.IncreaseOutputSize(CommandBackend.line);
         return("NoClip = " + noClip + "\nFlying = " + flying);
     }, "Toggle player collisions and flying.", CommandBackend.CommandType.Cheat);
     CommandBackend.AddConCommand("fly", (string[] args) =>
     {
         flying = !flying;
         return("Flying = " + flying);
     }, "Toggle player flying.", CommandBackend.CommandType.Cheat);
     CommandBackend.AddConCommand("speed", (string[] args) =>
     {
         if (args == null || args.Length == 0)
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             return("Player speed is set to " + playerSpeed + ".\nUsage: speed [float]");
         }
         else
         {
             playerSpeed = float.Parse(args[0]);
             return("Desired speed has been set.");
         }
     }, "Sets the player speed.", CommandBackend.CommandType.Cheat);
     CommandBackend.AddConCommand("jumpheight", (string[] args) =>
     {
         if (args == null || args.Length == 0)
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             return("Player jump height is set to " + jumpHeight + ".\nUsage: jumpheight [float]");
         }
         else
         {
             jumpHeight = float.Parse(args[0]);
             return("Desired jump height has been set.");
         }
     }, "Sets the player jump height.", CommandBackend.CommandType.Cheat);
 }
 public void Start()
 {
     CommandBackend.AddConCommand("help", (string[] args) =>
     {
         string helpmenu = "";
         if (args == null || args.Length == 0)
         {
             helpmenu = "Commands:";
             foreach (KeyValuePair <string, ConCommand> conCommand in CommandBackend.commands)
             {
                 if (conCommand.Value.type <= CommandBackend.allowedCommands)
                 {
                     helpmenu += "\n- " + conCommand.Key;
                     CommandBackend.IncreaseOutputSize(CommandBackend.line);
                 }
             }
             helpmenu += "\nUsage: help [string]";
         }
         else
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.commands[args[0]].helpOutputIncrement);
             helpmenu += "\"" + CommandBackend.commands[args[0]].help + "\"";
         }
         return(helpmenu);
     }, "Displays the help menu.");
     CommandBackend.AddConCommand("exit", (string[] args) =>
     {
         consoleWindow.gameObject.SetActive(false);
         CommandBackend.currentlyActive = false;
         return("Exiting console window...");
     }, "Exits the console window.");
     CommandBackend.AddConCommand("quit", (string[] args) =>
     {
         Application.Quit();
         #if UNITY_EDITOR
         EditorApplication.ExitPlaymode();
         #endif
         return("Successfuly quit the game.");
     }, "Quits the game.");
     CommandBackend.AddConCommand("clear", (string[] args) =>
     {
         CommandBackend.consoleLog = "";
         consoleLog.text           = "";
         CommandBackend.SetOutputSize(CommandBackend.line);
         return("Type \"exit\" to exit this console window.");
     }, "Clears and resets the console window.");
     CommandBackend.AddConCommand("fontsize", (string[] args) =>
     {
         if (args == null || args.Length == 0)
         {
             CommandBackend.IncreaseOutputSize(CommandBackend.line);
             return("Font size is set to " + consoleLog.fontSize + ".\nUsage: fontsize [int]");
         }
         else
         {
             consoleLog.fontSize = int.Parse(args[0]);
             return("Desired size has been set.");
         }
     }, "Sets the font size of the console window.");
     CommandBackend.AddConCommand("nextmap", (string[] args) =>
     {
         int index = SceneManager.GetActiveScene().buildIndex + 1;
         SceneManager.LoadScene(index);
         return("Loaded " + index + "!");
     }, "Loads the next map in order.");
     CommandBackend.AddConCommand("lastmap", (string[] args) =>
     {
         int index = SceneManager.GetActiveScene().buildIndex - 1;
         if (index >= 0)
         {
             SceneManager.LoadScene(index);
             return("Loaded " + index + "!");
         }
         else
         {
             return("Map index " + index + " is out of range!");
         }
     }, "Loads the next map in order.");
     CommandBackend.AddConCommand("allowcheats", (string[] args) =>
     {
         if (CommandBackend.allowedCommands < CommandBackend.CommandType.Cheat)
         {
             CommandBackend.allowedCommands = CommandBackend.CommandType.Cheat;
             return("Cheats have been enabled.");
         }
         else
         {
             return("The allowed commands are set to a higher enum than the parameter.");
         }
     }, "Activates cheats.");
     #if UNITY_EDITOR
     CommandBackend.AddConCommand("allowdev", (string[] args) =>
     {
         if (CommandBackend.allowedCommands < CommandBackend.CommandType.Developer)
         {
             CommandBackend.allowedCommands = CommandBackend.CommandType.Developer;
             return("Developer mode has been enabled.");
         }
         else
         {
             return("The allowed commands are set to a higher enum than the parameter.");
         }
     }, "Activates developer mode.");
     #endif
 }
Пример #4
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;
        }
    }