- Home /
How to make UI/canvas displayed trough gameobject/world-space-canvas
So i tried to make Red-dot sight for my shooter game, that works like irl ones where you can see the dot virtualy being far in front of the gun and see it only when looking trough the sight's glass.
I thought to do so by making the dot being always fixed in the center of the screen and having some physical GameObject/canvas in world-space that when some part of it is in the center of the screen it would work like mask and show the dot - otherwise the dot should be not visible. However i have no idea how to make the image fixed but its mask being able to move (with canvas solution) or how to make gamObject a mask for some image (with GameObject solution)
Is there a way to do it? Or is there some other way to imitate red-dot sight in game?
Answer by MSplitz-PsychoK · Aug 08, 2019 at 11:47 PM
Using a UI mask and image will be difficult because you need the image and mask to be a child of the canvas, and the mask will also need to be a child of your "sight", which makes the hierarchy very messy.
A much easier solution would be to use a SpriteMask because it does basically the same thing as an image mask, but the hierarchy does not matter at all. Your SpriteMask can be a child of your "sight", and the red dot sprite can be a child of your camera (or anything else you choose). Just make sure to select the "visible inside mask" Mask Interaction option for your red dot sprite.
Your answer
Follow this Question
Related Questions
Masking GameObject in Canvas 1 Answer
Flipping shot point 2d shooter 1 Answer
Can I combine 2 or more UI masks? 0 Answers
Aiming down sights 4 Answers
Rect Mask 2D won't update if I move 0 Answers