c# - Gameobject instantiated in canvas shows up behind other canvas items -
in game, if first time player has ever played game have image displayed. instantiate in canvas so:
if (playerprefs.getint("first time", 1) == 1) { introenabled = true; //pause activity pause.pauseorresume(); intro = instantiate (resources.load ("intro"), transform.position, quaternion.identity) gameobject; canvas canvas = gameobject.find("canvas").getcomponent<canvas>(); intro.transform.setparent(canvas.transform, false); //robot = instantiate (resources.load ("robot"), transform.position, quaternion.identity) gameobject; playerprefs.setint("first time", 0); playerprefs.save(); }
i can see in inspector when game running when object created, show in canvas. have no idea why won't show on top of of other objects in canvas.
the canvas rendering mode set "screen space - overlay" , set 0 in sort order. game object being instantiated has sort order of 0 , in default layer.
nothing have tried has worked. z values make no difference , putting canvas , instantiated object in default layer , setting canvas sort order of 2 , instantiated object sort order of 1 (so rendered first) not make difference.
what want use transform.setaslastsibling()
. canvasrenderer
renders gameobject
s in order according sibling index's (position in hierarchy), top bottom.
however, after examining code further noticed , should if trying instantiate intro screen, highly recommend instantiate it's own canvas
, instead of parenting existing one. significant should have it's own dedicated canvas
.
update: problem here instantiating gameobjects
transform
, sprite
renderer. canvas
ui gets rendered last, on mesh layers, if want newly instantiated gameobjects
participate, need have recttransform
, image
components instead.
Comments
Post a Comment