Advertisement
Wyvern67

Draw a colorpicker

Jul 25th, 2014
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. public class BuildingTexture : MonoBehaviour {
  2.     private float colorStep = 3/128; //   1/(256/6) this*42 is nearly 1
  3.     private Color tempColor = new Color (1,0,0,1);
  4.     public Texture2D tex = new Texture2D (256, 256);
  5.    
  6.     // Use this for initialization
  7.     void Start () {
  8.         renderer.material.mainTexture = tex;
  9.         for (int x=0; x<=42; x++) { //42 steps in each for loops
  10.             tempColor.g = tempColor.g+colorStep;
  11.             drawLine(x,tempColor);
  12.         }
  13.         for (int x=43; x<=84; x++) {
  14.             tempColor.r = tempColor.r-colorStep;
  15.             drawLine(x,tempColor);
  16.         }
  17.         for (int x=85; x<=127; x++) {
  18.             tempColor.b = tempColor.b+colorStep;
  19.             drawLine(x,tempColor);
  20.         }
  21.         for (int x=128; x<=170; x++) {
  22.             tempColor.g = tempColor.g-colorStep;
  23.             drawLine(x,tempColor);
  24.         }
  25.         for (int x=171; x<=212; x++) {
  26.             tempColor.r = tempColor.r+colorStep;
  27.             drawLine(x,tempColor);
  28.         }
  29.         for (int x=213; x<=256; x++) {
  30.             tempColor.b = tempColor.b-colorStep;
  31.             drawLine(x,tempColor);
  32.         }
  33.  
  34.         tex.Apply();
  35.         Debug.Log (tex);
  36.     }
  37.  
  38.     void drawLine(int x, Color tempColor){
  39.         Debug.Log(tempColor);
  40.         for (int y=0; y<256; y++) {
  41.             tex.SetPixel (x, y, tempColor);
  42.         }
  43.     }
  44.        
  45.     // Update is called once per frame
  46.     void Update () {
  47.    
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement