Can we colour a part of the Sprite .
I am having a white sprite of some shape what i want is to give different colour to half of it and different to half . which component i could use for doing that. Or if we can't do it with spriteRenderer ,any other component that would help me . I have never gone for colouring uv or vertices ,is that what is required , i just want a direction any tutorial or guide will be nice.
Yes, you have to split UV in half and color both half saperately. This can be done by creating fragment shader. To get started copy the UnlitColorShader and change it's fragment function.
What other shader would best suite me , On mobile platform as my scene is not much effected by lighting .
@Yash Sorry ,for the silly question but how do i write this fragment function . I mean i gave the material an unlit shader , can get the shader component or i have to write some class for shader , Can you refer some resource or guide for that .
Are the halves always made the same way, like always left and right? If so, seems simpler to make a sprite for each half. Can custom color each version, to make it look nice (ex: green Sue has a green shirt and hair, but not green skin.)
Then, there are tricks, like putting a semi-transparent red square over one half.
No the halves are not always made the same way . Infact i'm gonna try different proportions not just halves.
okey, so as you want your halves to be of any shape, you should use mask texture, it is a texture which will say which part will be of which color. for example if mask texture is black and white you can tell shader to effect all white part with red(or any color) and black with blue(or any color).
$$anonymous$$ching you about fragment shader will be out of scope for this comment but refer to unity's vertex shader documentation and start from there.
what you need to do in fragment shader is: get a color from real/sprite texture(sc) -> get a color from mask texture(mc) -> if mc is white multiply sc with your color1 else multiply sc with color2 -> return that color (fragment functions return color).
Good luck
I feel silly for not writing this before: searching for "unity color part of sprite" brings up other answered Qs about this.
Your answer
Follow this Question
Related Questions
How to change the camera background colour with player height. 1 Answer
Why Color.Lerp or Color32.Lerp doesnt work properly? 1 Answer
Is there any way to make a gradient within unity?,Is there any way to make a gradient? 1 Answer
Time.deltaTime getting faster each time 2 Answers
How to make RANDOM COLOR on shader 1 Answer