Unity2Dでいわゆるお絵描きアプリを作っています。
あらかじめ用意したSprite上でマウスをドラッグして色を塗りたいのですが、
"Unsupported texture format - needs to be ARGB32, RGBA32, RGB24, Alpha8 or one of float formats"
というエラーに阻まれて上手くいきません。
どこを間違えているのか、ご教授お願い致します。
試したこと:
Spriteの元の画像のImportSettingsで、"Read/Write Enabled"にチェック。
PC,Mac&Linux Standalone Settingsから、"Override for PC~~"にチェック。
Formatを"RGBA 32bit"に変更。
RGBA32bit以外にもエラー文で推奨されているformatは全て試したのですが、どれも変わらず上記のエラーが出てしまいました。
以下が色を塗るスクリプトです。
public class Nuru : MonoBehaviour { public SpriteRenderer sp; private Texture2D tx; private Brush brush; public class Brush { public int tate = 5; public int yoko = 5; public Color brushColor = new Color(0,0,0,0);//元が真っ黒なSpriteで、塗った場所が透明になるようにしようとしています。 public Color[] brushArea; public void BrushSet() { brushArea = new Color[tate * yoko]; for(int x = 0; x < brushArea.Length; x++) { brushArea[x] = brushColor; } } } // Use this for initialization void Start () { tx = sp.sprite.texture; brush = new Brush(); } // Update is called once per frame void Update () { if (Input.GetMouseButton(0)) { DrawLine(Input.mousePosition); } } private void DrawLine(Vector2 pos) { tx.SetPixels((int)pos.x, (int)pos.y, brush.yoko, brush.tate, brush.brushArea); tx.Apply(); } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/10 08:58