Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Anchoring a sprite to a corner? Code? UI Canvas?

Discussion in '2D' started by 39thstreet, Jun 7, 2018.

  1. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
    This seems like a dead simple question I have failed to answer for myself after searching for a while, hopefully someone can help.

    I've recently switched from 2dtoolkit to Unity Sprites, and one of the things I am *badly* missing is 2dtk Camera Anchors. I can not find an equivalent in native Unity.

    Let's say I want a sprite (or even any gameObject really) to be anchoring into the bottom right corner.

    Here's what I could do as I understand it:
    1. Write my own script to attach to the object which positions it based on the camera viewport.
    2. Use UI elements (canvas, rect transform, etc) and lay it out with the Unity UI tools.

    These both *work* but are they *right*? Using UI for a game element that is layered amongst other game elements seems wrong? The script works, but it's clunky when I'm testing aspect ratios in the editor and the like.

    Is there something obvious I'm missing here?