Ejemplo n.º 1
0
    /// <summary>
    /// The directional driver for the player core, returns a vector based on current inputs
    /// </summary>
    /// <returns>a directional vector based on current inputs</returns>
    public Vector2 getDirectionalInput()
    {
        if (Input.GetMouseButton(1) && !(MouseMovementVisualScript.overMinimap && Input.GetMouseButton(0)))
        {
            minimapPoint = null;
            // The angle from center of the screen to the mouse position on screen
            var delta = Input.mousePosition - new Vector3(Screen.width, Screen.height, 0) * 0.5f;
            return(delta.normalized);
        }

        if (Input.GetMouseButton(0) && MouseMovementVisualScript.overMinimap && !SelectionBoxScript.GetClicking())
        {
            minimapPoint = CameraScript.instance.minimapCamera.ScreenToWorldPoint(MouseMovementVisualScript.GetMousePosOnMinimap());
            minimapPoint = new Vector3(minimapPoint.Value.x, minimapPoint.Value.y, 0);
            var delta = minimapPoint.Value - transform.position;

            return(delta.normalized);
        }

        //Sum up all inputs
        Vector2 direction = Vector2.zero;

        if (InputManager.GetKey(KeyName.Up))
        {
            direction += new Vector2(0, 1);
        }

        if (InputManager.GetKey(KeyName.Left))
        {
            direction += new Vector2(-1, 0);
        }

        if (InputManager.GetKey(KeyName.Down))
        {
            direction += new Vector2(0, -1);
        }

        if (InputManager.GetKey(KeyName.Right))
        {
            direction += new Vector2(1, 0);
        }

        if (minimapPoint != null && direction == Vector2.zero)
        {
            if (Vector3.SqrMagnitude(transform.position - minimapPoint.Value) < PathAI.minDist)
            {
                minimapPoint = null;
                return(Vector2.zero);
            }
            else
            {
                return((minimapPoint.Value - transform.position).normalized);
            }
        }
        else
        {
            minimapPoint = null;
        }

        //Send unit vector
        direction.Normalize();
        return(direction);
    }
Ejemplo n.º 2
0
 void Awake()
 {
     instance            = this;
     simpleMouseMovement = PlayerPrefs.GetString("SelectionBoxScript_simpleMouseMovement", "True") == "True";
 }