Skip to main content
added 732 characters in body
Source Link

Thanks to @DMGregory's response, I was able to get this working using the SetVerticesDirty() method from the UnityEngine.UI.Graphic class.

So to get the above horrible code udating the triangles in realtime, i could simply modify the update method as follows:

private void Update()
{
    if (flipped)
    {
        Verts[2] = new Vector3(Verts[2].x + Time.deltaTime * speed, Verts[2].y, Verts[2].z);
    }
    else
    {
        Verts[2] = new Vector3(Verts[2].x - Time.deltaTime * speed, Verts[2].y, Verts[2].z);
    }

    if (Verts[2].x > orig.x + freedom || Verts[2].x < orig.x - freedom)
    {
        flipped = !flipped;
        Verts[2] = new Vector3(Mathf.Clamp(Verts[2].x, orig.x - freedom, orig.x + freedom), Verts[2].y, Verts[2].z);
    }
    SetVerticesDirty();
}

Thanks to @DMGregory's response, I was able to get this working using the SetVerticesDirty() method from the UnityEngine.UI.Graphic class.

Thanks to @DMGregory's response, I was able to get this working using the SetVerticesDirty() method from the UnityEngine.UI.Graphic class.

So to get the above horrible code udating the triangles in realtime, i could simply modify the update method as follows:

private void Update()
{
    if (flipped)
    {
        Verts[2] = new Vector3(Verts[2].x + Time.deltaTime * speed, Verts[2].y, Verts[2].z);
    }
    else
    {
        Verts[2] = new Vector3(Verts[2].x - Time.deltaTime * speed, Verts[2].y, Verts[2].z);
    }

    if (Verts[2].x > orig.x + freedom || Verts[2].x < orig.x - freedom)
    {
        flipped = !flipped;
        Verts[2] = new Vector3(Mathf.Clamp(Verts[2].x, orig.x - freedom, orig.x + freedom), Verts[2].y, Verts[2].z);
    }
    SetVerticesDirty();
}
Source Link

Thanks to @DMGregory's response, I was able to get this working using the SetVerticesDirty() method from the UnityEngine.UI.Graphic class.