I have a mini-game the player will clean the dust from the part, I will put a sprite of dust on top, and by wiping, a clean material will write over the dust one and it will appear clean and the dust will go away, but I don’t know how to identify when will the task is done. Do you guys have any suggestions on how to identify how percentage the brush have cover the dust.
using UnityEngine;
using System.Collections;
public class MaskCamera : MonoBehaviour
{
public Material EraserMaterial;
public Camera camera;
private bool firstFrame;
private Vector2? newHolePosition;
private void CutHole(Vector2 imageSize, Vector2 imageLocalPosition)
{
Rect textureRect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
Rect positionRect = new Rect(
(imageLocalPosition.x - 0.5f * EraserMaterial.mainTexture.width) / imageSize.x,
(imageLocalPosition.y - 0.5f * EraserMaterial.mainTexture.height) / imageSize.y,
EraserMaterial.mainTexture.width / imageSize.x,
EraserMaterial.mainTexture.height / imageSize.y
);
Debug.Log(positionRect);
GL.PushMatrix();
GL.LoadOrtho();
for (int i = 0; i < EraserMaterial.passCount; i++)
{
EraserMaterial.SetPass(i);
GL.Begin(GL.QUADS);
GL.Color(Color.red);
GL.TexCoord2(textureRect.xMin, textureRect.yMax);
GL.Vertex3(positionRect.xMin, positionRect.yMax, 0.0f);
GL.TexCoord2(textureRect.xMax, textureRect.yMax);
GL.Vertex3(positionRect.xMax, positionRect.yMax, 0.0f);
GL.TexCoord2(textureRect.xMax, textureRect.yMin);
GL.Vertex3(positionRect.xMax, positionRect.yMin, 0.0f);
GL.TexCoord2(textureRect.xMin, textureRect.yMin);
GL.Vertex3(positionRect.xMin, positionRect.yMin, 0.0f);
GL.End();
}
GL.PopMatrix();
}
public void Start()
{
firstFrame = true;
}
public void Update()
{
newHolePosition = null;
if((CursorImage.currImage != null))
if (Input.GetMouseButton(0) &&(CursorImage.currImage.name == "Cloth"))
{
Vector2 v = camera.ScreenToWorldPoint(Input.mousePosition);
Rect worldRect = new Rect(-292, -145, 592, 278);
if (worldRect.Contains(v))
{
newHolePosition = new Vector2(1200 * (v.x - worldRect.xMin) / worldRect.width, 800 * (v.y - worldRect.yMin) / worldRect.height);
}
}
}
public void OnPostRender()
{
if (firstFrame)
{
firstFrame = false;
GL.Clear(false, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));
}
if (newHolePosition != null)
CutHole(new Vector2(1200, 800), newHolePosition.Value);
}
}
Here is the code