2
votes

Super basic question that I cant seem to find an answer to:

All I've done is create a new 2D unity project and added a single sprite to the scene. I add a C# script to the sprite and set its position to a new Vector2(0,0). When run, the sprite moves its center point to the center of the screen, as opposed to the bottom left corner. This is also the case when I set the position of the spite to 0,0 in the editor. I've tried making the sprite a child of the camera, and I've tried using WorldToScreenPoint(). It's been awhile since I've used Unity so I must not be understanding something.

Thanks for the help

Edit: As suggested here's the single line of code in question, don't think this will add much clarity.

public class NewBehaviourScript : MonoBehaviour {

// Use this for initialization
void Start () {
    this.transform.position = new Vector2 (0, 0);
}

// Update is called once per frame
void Update () {

}

}

enter image description here

1
Without your code, how can anyone find your problem? - Programmer
With your edit, you haven't asked a question yet. What are you expecting? - Programmer
If I understand correctly you just have to move your camera so the center of the camera is not in the center of the world (the origin). - Lestat

1 Answers

1
votes

Unity renders based on the camera's frustum, not an arbitrary screen pixel position (unless you translate such to the frustum through a script).

By default, the camera will "look" at the scene-space origin (0, 0), and if you put your sprite there, of course it will be centered on screen on play.


[EDIT]

BTW, from...

I've tried making the sprite a child of the camera, and I've tried using WorldToScreenPoint().

... it seems you're trying to put a sprite somewhere in relation to the camera. If that's for GUI, the correct way to do it is not as a child of the camera. Instead, use a screen-space Canvas. Screen-space canvasses, unlike cameras, work based on pixel position, too! =)