- Home /
draw and compare
I need to do something geared towards education for a college job, I thought of making a game where the child sees a placheholder of a vowel and clicking on the image she can paint and when the image is all painted will appear a fireworks and a sound of congratulations , can anyone tell me how I do the painting system and know that what he painted and the right vowel?
Answer by toddisarockstar · Oct 15, 2017 at 04:57 PM
to script a paint program the basic concept would be to use Texture2D.setpixel.
where you can assign new colors to pixels in a texture with two coordinates. you would use:
Input.mousePosition and screen.width and screen.height and multiply/devide according to get your pixel location to paint on the texture.
here is very simple example:
Texture2D paper;
public float mx,my;
void Start () {
paper = new Texture2D (200,100);
paper.filterMode = FilterMode.Point;}
void Update () {
mx = Input.mousePosition.x;
my = Input.mousePosition.y;
if (Input.GetMouseButton (0)) {
mx=(mx/Screen.width)*paper.width;
my=(my/Screen.height)*paper.height;
paper.SetPixel((int)mx,(int)my,Color.black);
paper.Apply();}}
void OnGUI(){
GUI.DrawTexture (new Rect(0, 0, Screen.width, Screen.height),paper);}
Your answer
Follow this Question
Related Questions
Drawing a straight line between two points with 2D UI 1 Answer
Multiple Cars not working 1 Answer
Making a arrow instead of Linerenderer 2 Answers
Distribute terrain in zones 3 Answers
Button Enabling/Disabling using Collision Triggers? 1 Answer