Unity Spawning Prefab

I am trying to create an assembly using a script. This is the code, the code is written inside the game bar.

Network.Instantiate (ninjaPreFab, new Vector3 (-53, -34, 0), Quaternion.identity, 0);

      

However, it does not multiply inside the canvas. Instead, it always appears outside of the canvas, which means that it is not a child of the canvas, so it does not appear inside the game as I am using Rendering - Overlay Camera. I tried setting the sort order for the canvas to -1, but still it doesn't work. I know this is spawned because the editor clearly shows that there is this new object.

+3


source to share


2 answers


The problem has been resolved. I shouldn't have run the game object / sprite inside the canvas. The canvas is for the user interface only.



0


source


If using the new Unity user interface, the GUI elements must be children of the canvas game object, and their coordinates must be set within the bounds of the canvas and not too close to the camera's clipping plane (within the clipping range) if they are to be visible on screen. If you're working with the UI canvas, take a look at the awesome Unity UI tutorials here .

As per your code snippet, it seems your UI elements are invisible due to the negative sign of the coordinate values. Try changing them to positive values ​​and see what happens. Also, the parent UI element on the canvas looks like this:



var newUIElement = Network.Instantiate (ninjaPreFab, new Vector3 (53, 34, 0), Quaternion.identity, 0);
newUIElement.transform.parent = canvas;

      

+3


source







All Articles