Exemple #1
0
    void Update()
    {
        const float rotationTime = 0.5f;

        if (rotating)
        {
            rotationTimer += Time.deltaTime;
            if (rotationTimer >= rotationTime)
            {
                transform.rotation = orientation2;
                playManager.CreatePlayableArea();
                rotating = false;
            }
            else
            {
                float t = rotationTimer / rotationTime;
                transform.rotation = Quaternion.Lerp(
                    orientation1, orientation2, t);
            }
        }
        else
        {
            int rotation = -1;
            if (!PlayManager.lockInput)
            {
                if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    rotation = 0;
                }
                else if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    rotation = 1;
                }
                else if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    rotation = 2;
                }
                else if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    rotation = 3;
                }
            }
            if (rotation != -1)
            {
                orientationIndex =
                    neighborIndices[orientationIndex, rotation];
                orientation1  = transform.rotation;
                orientation2  = orientations[orientationIndex];
                rotationTimer = 0f;
                rotating      = true;
            }
        }
    }
Exemple #2
0
    IEnumerator SnapToRotation()
    {
        if (dragDir.magnitude >= minSwipeLength)
        {
            playManager.DeselectCube();
        }
        while (transform.rotation != toRotation)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, Time.deltaTime * lerpSpeed);
            yield return(null);
        }

        transform.rotation = toRotation;
        cuboid.ToggleParent();
        toRotation         = Quaternion.Euler(0, 0, 0);
        transform.rotation = Quaternion.identity;
        cuboid.ToggleParent();
        isRotating = false;
        playManager.CreatePlayableArea();
        PlayManager.lockInput = false;
    }