Exemplo n.º 1
0
        public static Vector3 RandomPoint(this MeshCollider that)
        {
            Bounds  bounds  = that.sharedMesh.bounds;
            Vector3 min     = bounds.min;
            Vector3 max     = bounds.max;
            Vector3 vector  = max - min;
            Vector3 vector2 = default(Vector3);

            for (int i = 0; i < 40; i++)
            {
                vector2.x = min.x + UnityEngine.Random.value * vector.x;
                vector2.y = min.y + UnityEngine.Random.value * vector.y;
                vector2.z = min.z + UnityEngine.Random.value * vector.z;
                if (that.IsPointInside(that.transform.TransformPoint(vector2)))
                {
                    break;
                }
            }
            return(vector2);
        }
Exemplo n.º 2
0
    static public Vector3 RandomPoint(this MeshCollider that)
    {
        var     bounds = that.sharedMesh.bounds;
        Vector3 min    = bounds.min;
        Vector3 max    = bounds.max;

        Vector3 range = (max - min);

        Vector3 p = new Vector3();

        for (int i = 0; i < 40; ++i)
        {
            p.x = min.x + Random.value * range.x;
            p.y = min.y + Random.value * range.y;
            p.z = min.z + Random.value * range.z;

            if (that.IsPointInside(that.transform.TransformPoint(p)))
            {
                break;
            }
        }

        return(p);
    }