Game Development Reference
In-Depth Information
012 public int SurfaceTextureHeight = 512;
013
014 //Reference to painting surface texture
015 public Texture2D SurfaceTexture = null;
016
017 //Reference to material for destination texture
018 public Material DestMat = null;
019 //-------------------------------------------------
020 // Use this for initialization
021 void Start ()
022 {
023 //Create destination texture
024 SurfaceTexture = new Texture2D(SurfaceTextureWidth,
SurfaceTextureHeight, TextureFormat.RGBA32, false);
025
026 //Fill with black pixels (transparent; alpha=0)
027 Color[] Pixels = SurfaceTexture.GetPixels();
028 for(int i=0; i<Pixels.Length; i++)
029 Pixels[i] = new Color(0,0,0,0);
030 SurfaceTexture.SetPixels(Pixels);
031 SurfaceTexture.Apply();
032
033 //Set as renderer main texture
034 renderer.material.mainTexture = SurfaceTexture;
035
036 //If destination material, set blend texture
037 //Used with custom shader
038 if(DestMat)
039 DestMat.SetTexture("_BlendTex", SurfaceTexture);
040 }
041 //--------------------------------------------------
042 // Update is called once per frame
043 void Update ()
044 {
045 //If mouse button down, then start painting
046 if(Input.GetMouseButtonDown(0))
047 {
048 //Get hit of mouse cursor
049 RaycastHit hit;
050
051 //Convert screen point to ray in scene
 
Search WWH ::




Custom Search