I am using DrawPixels on a Texture2D in order to create a painting style application. However, it draws squares which will give a very rough edge. Is it possible to have a more rounded look? Here is my code:
using UnityEngine;
using System.Collections;
public class PaintControl : MonoBehaviour
{
public Transform plane;
public Color color;
public int Size;
private RaycastHit hit;
private Color[] paintColors;
// Use this for initialization
void Start ()
{
// init the texture to white
Texture2D texToWhite = plane.renderer.material.mainTexture as Texture2D;
Color[] fillColorArray = texToWhite.GetPixels();
for (int i = 0; i < fillColorArray.Length; ++i)
fillColorArray *= Color.white;*
texToWhite.SetPixels(fillColorArray);
texToWhite.Apply();
SetColor(this.color);
- }*
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
Ray theRay = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(theRay, out hit, 50.0f))
{
GameObject go = hit.collider.gameObject;
if (go.tag == “DrawCanvas”)
{
Debug.Log(Input.mousePosition);
Renderer render= hit.collider.renderer;
MeshCollider meshColl = hit.collider as MeshCollider;
Texture2D tex = render.material.mainTexture as Texture2D;
Vector2 pixelUV = hit.textureCoord;
pixelUV.x *= tex.width;
pixelUV.y *= tex.height;
//tex.SetPixel((int)pixelUV.x, (int)pixelUV.y, Color.black);
tex.SetPixels((int)pixelUV.x, (int)pixelUV.y, this.Size, this.Size, paintColors);
tex.Apply();
}
}
}
- }*
public void SetColor(Color tempColor)
{
this.color = tempColor;
SetSize(this.Size);
}
public void SetSize(int tempSize)
{
this.Size = tempSize;
paintColors = new Color[tempSize * tempSize];
for (int i = 0; i < paintColors.Length; i++)
paintColors = this.color;
}
}