There is a 2D game. It is necessary to make objects, except for the player, at a certain moment black and white (all or selectively), and then under a certain condition, for example, he will collect 100 coins, make it colored. How to implement it? Experimented with gameObject.GetComponent (). Material.color - some kind of nonsense ...
Closed due to the fact that it was off topic by aleksandr barakin , 0xdb , user192664, user300000, nick_n_a October 24, '18 at 7:24 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - aleksandr barakin, nick_n_a
2 answers
gameObject.GetComponent().material.color - look in the wrong direction. In your situation, I would look in the direction of the shader or post effect.
The basic idea is that you only need the player to draw in non-black and white shades, then make a post-effect on the camera that will draw all the objects except the player. And the player himself can draw another camera.
Look, for example, this tutorial on a black and white post-effect. In this solution, there is only one controversial point - post effects can be a very expensive solution in terms of performance, so you need to experiment and look at performance. However, the transition from black and white and back will be easy to switch and you do not need to have links to all objects.
If you are developing for standalone platforms, then there should be no problems, but with mobile platforms such problems are possible.
- Thank! Torture Shaders - Michael Reed
- @MichaelReed If the answer was useful to you, please mark it as correct - vmchar
- An incomplete answer, this solution with the application of the post effect to certain objects must be correctly applied, just the shader is not enough. - RiotBr3aker
- @ RiotBr3aker in question is about all objects except the player - if you draw it with a separate camera, all questions disappear and everything is solved by 1 post effect - vmchar
- Well, then add this information in response :) - RiotBr3aker
I would look in the direction of the next path:
Create 2 cameras. Both are looking the same way and have the same visualization settings.
- On one camera you mark the display of all layers near the Selected layer.
- On the second - the opposite. And hang a grayscale script.
Then you need to render 2 cameras one above the second. I won't tell you the details how to do this, but you can make it to anyone.