Пример #1
0
    void checkNumber()
    {
        float bestDot = -1;

        for (int i = 0; i < vectorPoints.Length; ++i)
        {
            var valueVector = vectorPoints[i];
            // Each side vector is in local object space. We need them in world space for our calculation.
            var worldSpaceValueVector = this.transform.localToWorldMatrix.MultiplyVector(valueVector);
            // Mathf.Arccos of the dot product can be used to get the angle of difference. You can use this to check for a tilt (perhaps requiring a reroll)
            float dot = Vector3.Dot(worldSpaceValueVector, Vector3.up);
            if (dot > bestDot)
            {
                // The vector with the greatest dot product is the vector in the most "up" direction. This is the current face selected.
                bestDot        = dot;
                selectedVector = i;
            }
        }

        selectedResult = vectorValues[selectedVector];
        Debug.Log(selectedResult);
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        float bestDot = -1;

        for (int i = 0; i < vectorPoints.Length; ++i)
        {
            var valueVector = vectorPoints[i];
            // Each side vector is in local object space. We need them in world space for our calculation.
            var worldSpaceValueVector = this.transform.localToWorldMatrix.MultiplyVector(valueVector);
            // Mathf.Arccos of the dot product can be used to get the angle of difference. You can use this to check for a tilt (perhaps requiring a reroll)
            float dot = Vector3.Dot(worldSpaceValueVector, Vector3.up);
            if (dot > bestDot)
            {
                // The vector with the greatest dot product is the vector in the most "up" direction. This is the current face selected.
                bestDot        = dot;
                selectedVector = i;
            }
        }

        selectedResult = vectorValues[selectedVector];

        //For Text Above Dice
        text.text = selectedResult.ToString();
        text.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 3f);
        text.transform.LookAt(text.transform.position + diceCam.transform.rotation * Vector3.forward, diceCam.transform.rotation * Vector3.up);


        //For dice despawn
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            RaycastHit hit;
            Ray        ray = diceCam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 1000f) && hit.collider.gameObject.tag == "Dice")
            {
                Destroy(hit.collider.gameObject);
            }
        }
    }