Ejemplo n.º 1
0
    void Move()
    {
        if (Pauser.IsPaused())
        {
            return;
        }

        HandleSnakeBodies();
        CreateSnakeBody();

        if (direction == Direction.Up)
        {
            transform.position += new Vector3(0, moveSpeed, 0);
        }
        else if (direction == Direction.Down)
        {
            transform.position += new Vector3(0, -moveSpeed, 0);
        }
        else if (direction == Direction.Right)
        {
            transform.position += new Vector3(moveSpeed, 0, 0);
        }
        else if (direction == Direction.Left)
        {
            transform.position += new Vector3(-moveSpeed, 0, 0);
        }

        lastMove = direction;

        Debug.Log("Player moved to " + transform.position);
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Pauser.IsPaused() && !Pauser.IsFirstPaused())
        {
            return;
        }

        // Only handles input
        if (Input.GetKey("w") && lastMove != Direction.Down)
        {
            direction             = Direction.Up;
            transform.eulerAngles = new Vector3(0, 0, 0);
        }
        else if (Input.GetKey("a") && lastMove != Direction.Right)
        {
            direction             = Direction.Left;
            transform.eulerAngles = new Vector3(0, 0, 90);
        }
        else if (Input.GetKey("s") && lastMove != Direction.Up)
        {
            direction             = Direction.Down;
            transform.eulerAngles = new Vector3(0, 0, 180);
        }
        else if (Input.GetKey("d") && lastMove != Direction.Left)
        {
            direction             = Direction.Right;
            transform.eulerAngles = new Vector3(0, 0, 270);
        }
    }