- Home /
SetPixel not working
I'm trying to make my own drawing application but I keep running into problems and despite there being very little room for error, I can't figure out my mistake.
I've created a RawImage in game world and have attached the following script.
RectTransform rect;
Texture2D canvas;
SpriteRenderer rend;
Vector2 mousePos = new Vector2();
public List<Sprite> los = new List<Sprite>();
void Start()
{
var ri = GetComponent<RawImage>();
rect = ri.GetComponent<RectTransform>();
rend = GetComponent<SpriteRenderer>();
Texture2D text = new Texture2D(400, 400);
for (int x = 0; x < text.width; x++)
{
for (int y = 0; y < text.height; y++)
{
text.SetPixel(x, y, Color.green);
}
}
text.Apply();
Sprite news = Sprite.Create(text, new Rect(0, 0, text.width, text.height), Vector2.one*0.5f);
rend.sprite = news;
}
However, nothing shows up! I've tried placing an image into the RawImage Texture component, playing with it's color and searching the game world for the sprite but nothing. One thing I am sure of is that my green block is being created because it shows up in the texture component of the SpriteRenderer and in my list of sprites but it never seems to show up on the screen itself.
Comment
Answer by dendyyyy · Jun 25, 2020 at 12:23 AM
What other options are there for resolving this issue?