Search Unity

Rotating and Offsetting a Sprite's Image

Discussion in 'Scripting' started by Nigey, Jul 3, 2015.

  1. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Hey Guys,

    I have an image, which is circular (like the edge of a compass measurements). I want to only show a portion of the image on the screen. Not only that, but I to show only a portion and rotate the texture before it's set to a sprite or an object. So in effect, I'm completely setting the position, rotation, and portion rendered of an image within a sprite. Not the sprite's rotation/position itself.

    To emulate this as best as I can I've currently got a 2nd camera on the screen, with objects attached to it, which are only shown by the filter of that second camera. The circular object spins within that second camera's view. That second camera is rendered on a portion of the viewport, so it looks like it's fitting into an overlaying image. However that's just an illusion. Overall it works, but it feels hacky and I don't like hacky.. And lengthy to edit. Can anyone think of another way to get the same effect? if not at least, like the way I suggested above.

    Thanks!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    using the new UI you could probably just have the sprite as a child of a mask and rotate the whole sprite object
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    You could use 2 sprites, one with the image & then a circular masking image with the same diameter & a segment cut out that is overlaid on it. Both could be rotated however you want on instantiation (in the same spot) to reveal different bits of the underlying image.
     
  4. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Thanks guys, seems to be working great!