Beispiel #1
0
    // Use this for initialization


    // Update is called once per frame
    void LateUpdate()
    {
        if (Input.GetMouseButton(0))
        {
            if (!canRotateSide)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100))
                {
                    isDisabled = true;

                    if (pieces.Count < 2 &&
                        !pieces.Exists(x => x == hit.collider.transform.parent.gameObject) &&
                        hit.transform.parent.gameObject != CubeMan.gameObject)
                    {
                        pieces.Add(hit.collider.transform.parent.gameObject);
                        planes.Add(hit.collider.gameObject);
                    }
                    else if (pieces.Count == 2)
                    {
                        CubeMan.DetectRotate(pieces, planes);
                        canRotateSide = true;
                    }
                }
            }
            if (!isDisabled)
            {
                isDisabled = false;
                if (!CubeMan.isReverse)
                {
                    localRotation.x += Input.GetAxis("Mouse X") * Buttons.xSens;
                    localRotation.y += Input.GetAxis("Mouse Y") * Buttons.ySens;
                }
                else
                {
                    localRotation.x += Input.GetAxis("Mouse X") * -Buttons.xSens;
                    localRotation.y += Input.GetAxis("Mouse Y") * -Buttons.ySens;
                }
                //нет перевращения кубика(нельзя развернууть его на 360 градусов)
                localRotation.y = Mathf.Clamp(localRotation.y, -90, 90);
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            pieces.Clear();
            planes.Clear();
            isDisabled = canRotateSide = false;
        }
        Quaternion qt = Quaternion.Euler(localRotation.y, localRotation.x, 0);

        transform.parent.rotation = Quaternion.Lerp(transform.parent.rotation, qt, Time.deltaTime * 15);
    }
Beispiel #2
0
    private void LateUpdate()
    {
        if (Input.GetMouseButton(0))
        {
            if (!rotateDisabled)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, 100))
                {
                    cameraDisabled = true;

                    if (pieces.Count < 2 &&
                        !pieces.Exists(x => x == hit.collider.transform.parent.gameObject) &&
                        hit.transform.parent.gameObject != cubeMan.gameObject)
                    {
                        pieces.Add(hit.collider.transform.parent.gameObject);
                        planes.Add(hit.collider.gameObject);
                    }

                    else if (pieces.Count == 2)
                    {
                        cubeMan.DetectRotate(pieces, planes);
                        rotateDisabled = true;
                    }
                }
            }

            if (!cameraDisabled)
            {
                rotateDisabled   = true;
                localRotation.x += Input.GetAxis("Mouse X") * 5;
                localRotation.y += Input.GetAxis("Mouse Y") * -5;
                localRotation.y  = Mathf.Clamp(localRotation.y, -90, 90);
            }
        }

        else if (Input.GetMouseButtonUp(0))
        {
            pieces.Clear();
            planes.Clear();
            cameraDisabled = rotateDisabled = false;
        }

        Quaternion qt = Quaternion.Euler(localRotation.y, localRotation.x, 0);

        transform.parent.rotation = Quaternion.Lerp(transform.parent.rotation, qt, Time.deltaTime * 15);
    }