It is necessary to display (by command in the script) image on the whole screen. Overlapping everything. From the idea - just create a second camera, put the picture to her as a background, at the right moment - switch to it. Is it possible to make it easier?
2 answers
Yes, there is no simpler option. Where can it be easier to enable ( SetActive(true) ) or disable ( SetActive(false) ) something at the right moment? One team for one action and one team for another.
The only thing is not to carry an extra camera, because you probably use the UI, you can immediately use this UI. Those.
Add an empty object to the
Canvas(i.e. UI). Call it Overlay and say its width and height occupy the entire screen:At this object, we add a descendant of
UI -> Image(Image accepts not a simple image for itself, but sprite. This means you need to make the image as a sprite. If you want a clean image, you can chooseRawImageinstead ofImage). Call the stream for example OverlayBackground .which you can assign a picture or just in the monotonous color to paint over or make transparency.
And in the end, specifically with this Overlay, we do what we want: we hide, show, assign backgrounds for the OverlayBackground , add some more objects, such as displaying the result of a game or menu or exit buttons, and so on.
And of course turn on or off at the right time.
Sample hierarchy:
- Thank! And how exactly in the script to turn it off or on? I realized that
(SetActive(true))or disable(SetActive(false))And how exactly? Script attach to OverlayImage? So what is next? - Dmitrii - oneThe @Dmitrii script you can have anywhere in general, in fact. Maybe on the player, maybe on the camera, maybe on the GameManager in general. And you should not disconnect OverlayImage, but the root, i.e. Overlay , because it can contain not only a picture on the whole screen, but something else (at your discretion, of course) ... And you can turn off the
GameObject.Find("/path/to/object").SetActive(false)objectGameObject.Find("/path/to/object").SetActive(false)or, for example, in the script you have apublic GameObject myOverlayfield in which you can drag the Overlay object itself and writemyOverlay.SetActive(false), etc., at the right time. - Alexey Shimansky - Thanks, I quickly figured out this issue, so I managed to remove it. How to stretch the picture? I chose stretch in the UI settings, the anchors were set at the edges of the screen and the image itself remained small. I tried to drive the necessary values into size - the picture expands, but on different devices there are different screen resolutions, how can you just stretch it to screen.height \ screen.width? - Dmitrii
- one@Dmitrii position is necessary to put the upper left corner of the main object (left = top = 0) and right = bottom = 0 too ... look in the answer ..... in a picture, in principle, too, all by zero is better to do - Alexey Shimansky
- one@Dmitrii well, it is as if logical. before turning something on you have to turn it off .... before you manipulate something - you need to have a link to it O_o This is the knowledge base - Alexey Shimansky
Very simple solution: using Image ( GUI ) with Canvas .
We add a new UI-> Image in the scene hierarchy
Make it stretchable using the bindings settings (done in the object inspector; click on the box at the top left and select the option you want)

- Make sure that the image will be at the bottom of the list of GUI elements in the Canvas; otherwise, other GUI elements will be visible over the image.
- Connect as you prefer image to your script


