- Home /
 
               Question by 
               fusecore · Feb 06, 2015 at 12:40 AM · 
                c#spritetexture2dspriterenderer  
              
 
              How do I fill a Texture2D with pixels and display a sprite with that texture using script?
Hi, I'm trying to make a little pixel transition a-la pokemon battle transition. To do that I need to write pixels per frame to a Texture2D and then set the gameobject's spriterenderer's sprite. My script creates a Texture2D as I want it, I can tell in the editor. But creating a Sprite from that doesn't seem to work.


     void Awake () {
         frame = new Texture2D(size, size);
         
         for (int x = 0; x < size; x++){
             for (int y = 0; y < size; y++){
                 frame.SetPixel(x, y, color); 
             }
         }
         frame.Apply();
     sprit=new Sprite();
         sprit=Sprite.Create(frame, new Rect(0f,0f,size,size), new Vector2(0f,0f));
         gameObject.GetComponent<SpriteRenderer>().sprite=sprit;
     }
 
                 
                8rvuq9.jpg 
                (4.6 kB) 
               
 
                
                 
                4w97pn.jpg 
                (5.1 kB) 
               
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by fusecore · Feb 06, 2015 at 04:03 PM
Solution: don't be stupid and have the alpha set to 0
Your answer
 
 
             Follow this Question
Related Questions
Slicing sliced sprite via script 0 Answers
Texturing custom 2d sprite 0 Answers
Strange behavour when drawing on texture 0 Answers
Can I create a sprite at runtime? 3 Answers
CMYK Image to Sprite render 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                