[Unity] How to make the particle system display on the UI?

    The first thing to know is why particle systems cannot be displayed on the UI.

    The reason is that the default rendering mode of Canvas is Screen-Overlay, which means that when Canvas is rendered in screen space, it will be displayed at the top of the scene, covering everything except the UI (the particle system is rendered in world space). , affected by the camera). At this time, the rendering of the Canvas is not affected by the Camera, and the scene can be rendered normally without a camera. The size of the Canvas changes with the resolution and viewport.

    So we have to modify the Render Mode of Canvas. There are also two modes: Screen-Camera and World Space.

    In Screen-Camera mode: You need to specify a rendering camera for Canvas, and the rendering process is affected by the parameters of the camera. At this time, Canvas is equivalent to a Plane at a certain distance from the camera. The UI size has nothing to do with the distance to the camera, but changes with the camera's Field of View. Perspective/head-up effects are also available.

    Because the Canvas is a Plane at a certain distance from the camera at this time, if there is an object that is closer to the camera than the Plane, it will be displayed above the Canvas, otherwise, it will be displayed below. If we drag the particle system under the Canvas to become its sub-object, and reset the Local Position to zero, we can see that the particle system is displayed on the UI. It is of course possible to modify its Z axis to be closer to the camera. (Doing this will turn the Transform of the particle system into a RectTransform, but this has no effect on its position, just the representation has changed)

   In World Space mode: Canvas is equivalent to a Plane in the scene, but Canvas still uses Rect Transform instead of Transform.    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325718375&siteId=291194637