Ejemplo n.º 1
0
    //Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp("o"))
        {
            control.Save();
        }
        else if (Input.GetKeyUp("p"))
        {
            control.Load();
        }


        // print(joystick.Horizontal + ";" + joystick.Vertical);
        float pointer_x = Input.GetAxisRaw("Horizontal");
        float pointer_y = Input.GetAxisRaw("Vertical");

        // if (Mathf.Abs(joystick.Horizontal) > 0.2f)
        // {
        //     pointer_x = joystick.Horizontal;
        // }

        // if (Mathf.Abs(joystick.Vertical) > 0.2f)
        // {
        //     pointer_y = joystick.Vertical;
        // }

        //if (Mathf.Abs(pointer_x) == 0f && Mathf.Abs(pointer_y) == 0f) isMovementOnDelay = false;

        //Debug.Log(pointer_x + ";" + pointer_y);

        // movement delay timer

        transform.position = Vector3.MoveTowards(transform.position, movePoint.position, playerMovementSpeed * Time.deltaTime);

        if (isMovementOnDelay)
        {
            movementDelayTimer += Time.deltaTime;
            if (movementDelayTimer >= movementDelayTime)
            {
                isMovementOnDelay  = false;
                movementDelayTimer = 0.0f;
            }
        }

        if (isMovementOnDelay)
        {
            return;
        }


        if (Vector3.Distance(transform.position, movePoint.position) <= 0.05F)
        {
            if (Mathf.Abs(pointer_x) == 1f)
            {
                isMovementOnDelay = true;
                if (Physics.OverlapSphere(movePoint.position + new Vector3(pointer_x * 1, 0f, 0f), 0.2f, whatStopsMovement).Length == 0)
                {
                    if (pointer_x == -1f)
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, -90, 0);
                    }
                    else
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, 90, 0);
                    }
                    //anim.SetBool("Hop", true);
                    movePoint.position += new Vector3(pointer_x, 0f, 0f);
                }
            }
            else if (Mathf.Abs(pointer_y) == 1f)
            {
                isMovementOnDelay = true;
                if (Physics.OverlapSphere(movePoint.position + new Vector3(0f, 0f, pointer_y * 1), 0.2f, whatStopsMovement).Length == 0)
                {
                    if (pointer_y == -1f)
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, 180, 0);
                    }
                    else
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
                    }
                    // anim.SetBool("Hop", true);
                    movePoint.position += new Vector3(0f, 0f, pointer_y);
                }
            }
        }
    }
Ejemplo n.º 2
0
 public void Save()
 {
     control.Save();
 }
Ejemplo n.º 3
0
    //Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp("o"))
        {
            control.Save();
        }
        else if (Input.GetKeyUp("p"))
        {
            control.Load();
        }


        print(joystick.Horizontal + ";" + joystick.Vertical);
        float pointer_x = Input.GetAxisRaw("Horizontal");
        float pointer_y = Input.GetAxisRaw("Vertical");

        // if (Mathf.Abs(joystick.Horizontal) > 0.2f)
        // {
        //     pointer_x = joystick.Horizontal;
        // }

        // if (Mathf.Abs(joystick.Vertical) > 0.2f)
        // {
        //     pointer_y = joystick.Vertical;
        // }

        if (Mathf.Abs(pointer_x) == 0f)
        {
            //Prevents holding down arrow keys to move, must release
            canMoveHorizontal = true;
        }

        if (Mathf.Abs(pointer_y) == 0f)
        {
            //Prevents holding down arrow keys to move, must release
            canMoveVertical = true;
        }

        //Debug.Log(pointer_x + ";" + pointer_y);

        transform.position = Vector3.MoveTowards(transform.position, movePoint.position, 20f * Time.deltaTime);
        if (Vector3.Distance(transform.position, movePoint.position) <= 0.05F)
        {
            if (Mathf.Abs(pointer_x) == 1f && canMoveHorizontal)
            {
                canMoveHorizontal = false;
                if (Physics.OverlapSphere(movePoint.position + new Vector3(pointer_x * 1, 0f, 0f), 0.2f, whatStopsMovement).Length == 0)
                {
                    if (pointer_x == -1f)
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, -90, 0);
                    }
                    else
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, 90, 0);
                    }
                    //anim.SetBool("Hop", true);
                    movePoint.position += new Vector3(pointer_x, 0f, 0f);
                }
            }
            else if (Mathf.Abs(pointer_y) == 1f && canMoveVertical)
            {
                canMoveVertical = false;
                if (Physics.OverlapSphere(movePoint.position + new Vector3(0f, 0f, pointer_y * 1), 0.2f, whatStopsMovement).Length == 0)
                {
                    if (pointer_y == -1f)
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, 180, 0);
                    }
                    else
                    {
                        gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
                    }
                    // anim.SetBool("Hop", true);
                    movePoint.position += new Vector3(0f, 0f, pointer_y);
                }
            }
            else
            {
                //anim.SetBool("Hop", false);
            }
        }
    }