c# - Create Rect at global coordinate -


my scene 2048 x 1152, , camera never moves. when create rectangle following:

timebarrect = new rect(220, 185, screen.width / 3, screen.height / 50); 

its position changes depending on resolution of game, can't figure out how land want on screen. clarify, if set resolution 16:9, , change size of preview window, game resize @ ratios of 16:9, bar move out it's supposed be.

i have 2 related questions:

  1. is possible place rect @ global coordinate? since screen 2048 x 1152, if place @ coordinate, it'd perfect.
  2. is rect ui element? when it's created, can't find in hierarchy. if it's ui element, feel should created relative canvas/camera, can't figure out way either.

update:

i realizing unclear being visualized. here information: once rect created, create texture, update size of texture in update() , draw rect in ongui():

timetexture = new texture2d (1, 1); timetexture.setpixel(0,0, color.green); timetexture.apply(); 

the texture size being changed:

void update ()      {         if (time < timermax) {             playercanattack = false;             time = time + (10 * time.deltatime);         } else {             time = timermax;             playercanattack = true;         } 

the actual visualization of rect, being drawn in different spot depending on size of screen:

void ongui(){      float ratio = time / 500;     float rectwidth = ratio * screen.width / 1.6f;     timebarrect.width = rectwidth;     gui.drawtexture (timebarrect, timetexture); } 

i don't know understand either of 2 questions posed, did discover way rect's coordinates match screen no matter resolution not using global coordinates, using camera's coordinates, , placing code in update() such rect's coordinates updated:

timebarrect.x = cam.pixelwidth / timerwidth; timebarrect.y = cam.pixelheight / timerheight; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -