Created
November 19, 2019 18:36
-
-
Save davepape/58540e68adab1cc5d1cd81a57f2e66b2 to your computer and use it in GitHub Desktop.
Create a Texture2D from scratch, and modify it slightly each frame.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class dynamicTexture : MonoBehaviour | |
{ | |
public int width=32; | |
public int height=32; | |
void Start() | |
{ | |
Texture2D texture = new Texture2D(width,height); | |
var pixels = texture.GetPixels32(0); | |
for (int j=0; j < height; j++) | |
{ | |
for (int i=0; i < width; i++) | |
{ | |
pixels[i+j*width] = new Color(j/(float)height,i/(float)width,0,0) + Random.ColorHSV()/10f; | |
} | |
} | |
texture.SetPixels32(pixels); | |
GetComponent<Renderer>().material.mainTexture = texture; | |
texture.Apply(); | |
} | |
void Update() | |
{ | |
Texture2D texture = (Texture2D) GetComponent<Renderer>().material.mainTexture; | |
texture.SetPixel(Random.Range(0,width), Random.Range(0,height), Color.black); | |
texture.Apply(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment