Saturday, November 9, 2019

unity - In Unity3D, how do I create an efficient scratch card effect?


I want to create a scratch-card-like effect in new Unity UI's new Image tag. I know it's possible with setPixels, but that's prohibitively expensive on mobile devices.


Something like this:


a real-life scratch card


I'd like the user to be able to drag on any part of the image to "scratch off" the top layer and reveal the content underneath it.


How can I do this?



Answer




I have done something similar to this in the past.


My solution to this would be to make use of Unity's new UI Mask and a Render Texture.


When the player touches the screen you would draw a circular sprite at that location and render it to a texture. You would then use this texture for the mask. Over time these sprites will reveal more and more of the image giving you the effect you are after without having to go down the SetPixels route.


This is a similar question that was asked which has a load of good links on it if you don't mind that it's XNA/C# but the concepts are the same.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...