Search Unity

Drawing shapes on a canvas

Discussion in '2D' started by killakiwi, Apr 27, 2016.

  1. killakiwi

    killakiwi

    Joined:
    Sep 5, 2013
    Posts:
    22
    Hello,

    I'm in a bit of a pickle because I am using an asset that requires my canvas use Overlay, but I also need to render a 2d octagon shape to the screen (and also be able to manipulate the vertices through code).

    I can get it all working if I use Camera mode (by having a octagon mesh and accessing its .vertices[] array. But then the other asset doesn't work.

    So I need to use Overlay mode, but I don't know how to render a 2d shape to it.

    Thanks :D
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Have you considered this asset?

    If you really want to roll your own, I think you can do it using CanvasRenderer, as discussed here. But Patrick has done a great job with the above asset, and it may be well worth the price to let him be the expert on these poorly-documented Canvas tricks.
     
  3. killakiwi

    killakiwi

    Joined:
    Sep 5, 2013
    Posts:
    22
    I discovered the UI Polgyon script in Unity Extensions which does exactly what I need out of the box. Perfect!.

    Thanks anyway
     
    JoeStrout likes this.
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,362
    UIPolygon uses VertexHelper and OnPopulateMesh which aren't in 4.7, what's the alternative?