0
\$\begingroup\$

how to replicate this type of scratch card effect in Unity3D considering its for mobile.

https://youtu.be/6wLWu1BefXs

Two cases 1. Clear part of screen where user touches. 2. How to trigger rewards after certain amount of image get reveal?

\$\endgroup\$
2
  • \$\begingroup\$ You can overlay 2 images and when you move over the top one it changes it's mask (like changing the alpha to 0 on mouseover so that the underlying image becomes visible) \$\endgroup\$
    – Dries
    Commented Jun 8, 2015 at 9:15
  • \$\begingroup\$ yes,but how to do it with Unity's new UI mask component? \$\endgroup\$
    – idurvesh
    Commented Jun 8, 2015 at 9:31

1 Answer 1

3
\$\begingroup\$

Create a Texture2d and assign it to the Mask component then use SetPixel to set the alpha of pixels beneath the players finger to 0.

SetPixel

1) Use EventTrigger Component to track OnPointerDown and OnDrag on your scratch card.

2) Interpolate pixels at touch location based on touch position and screen size of Scratch Card.

3) Set pixels in Mask Texture to alpha = 0 where touched.

4) Apply changes to Texture2d.

\$\endgroup\$
3
  • \$\begingroup\$ thanks for kind ans,does setPixels slow on mobile? and how will I know how much portion of image user has wipe out so that I can reveal user rewards \$\endgroup\$
    – idurvesh
    Commented Jun 8, 2015 at 10:03
  • \$\begingroup\$ SetPixel isn't the fastest operation since it requires the texture to be sent back to the GPU each time you apply the changes but for a situation like a scratch card like this it should work fine. To track how much of the card has been revealed just count the number of pixels you have set to alpha 0 and store the number each update. When that number reaches a certain threshold compared to the number of pixels in the Mask texture, consider the card scratched enough and show the reward. \$\endgroup\$ Commented Jun 8, 2015 at 10:07
  • \$\begingroup\$ thanks, with modifications to this link I able to get it work on uGUI studio.openxcell.com/remove-dustfog-object-unity-swipe.html \$\endgroup\$
    – idurvesh
    Commented Jun 8, 2015 at 13:59

Not the answer you're looking for? Browse other questions tagged .