Beispiel #1
0
    private void Update()
    {
        float   num      = Time.time * speed;
        Vector3 position = new Vector3(Mathf.PerlinNoise(num, num) * travel, 2f, Mathf.PerlinNoise(num + 1f, num + 1f) * travel);

        base.transform.position = position;
        if (target == null)
        {
            Debug.LogWarning("Missing the ProBuilder Mesh target!");
            return;
        }
        Vector3 a = target.transform.InverseTransformPoint(base.transform.position);

        if (nearest != null)
        {
            target.SetFaceColor(nearest, Color.white);
        }
        int   num2 = target.faces.Length;
        float num3 = float.PositiveInfinity;

        nearest = target.faces[0];
        for (int i = 0; i < num2; i++)
        {
            float num4 = Vector3.Distance(a, FaceCenter(target, target.faces[i]));
            if (num4 < num3)
            {
                num3    = num4;
                nearest = target.faces[i];
            }
        }
        target.SetFaceColor(nearest, Color.blue);
        target.RefreshColors();
    }
Beispiel #2
0
    void Update()
    {
        float time = Time.time * speed;

        Vector3 position = new Vector3(
            Mathf.PerlinNoise(time, time) * travel,
            2,
            Mathf.PerlinNoise(time + 1f, time + 1f) * travel
            );

        transform.position = position;

        if (target == null)
        {
            Debug.LogWarning("Missing the ProBuilder Mesh target!");
            return;
        }

        // instead of testing distance by converting each face's center to world space,
        // convert the world space of this object to the pb-Object local transform.
        Vector3 pbRelativePosition = target.transform.InverseTransformPoint(transform.position);

        // reset the last colored face to white
        if (nearest != null)
        {
            target.SetFaceColor(nearest, Color.white);
        }

        // iterate each face in the pb_Object looking for the one nearest
        // to this object.
        int   faceCount        = target.faces.Length;
        float smallestDistance = Mathf.Infinity;

        nearest = target.faces[0];

        for (int i = 0; i < faceCount; i++)
        {
            float distance = Vector3.Distance(pbRelativePosition, FaceCenter(target, target.faces[i]));

            if (distance < smallestDistance)
            {
                smallestDistance = distance;
                nearest          = target.faces[i];
            }
        }

        // Set a single face's vertex colors.  If you're updating more than one face, consider using
        // the pb_Object.SetColors(Color[] colors); function instead.
        target.SetFaceColor(nearest, Color.blue);

        // Apply the stored vertex color array to the Unity mesh.
        target.RefreshColors();
    }