Hi,
I create a dynamic texture2D(“_dynamicTexture”) and when I run the scene, the sprite objet does not display the new texture with my shader.
How can I apply it correctly and not get my white ish result(as shown below)?
This is my test code:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public Color _testColor;
private Texture2D _dynamicTexture;
private void Start(){
Sprite selfSprite = GetComponent<SpriteRenderer> ().sprite;
int width = (int)(selfSprite.bounds.max.x - selfSprite.bounds.min.x);
int height = (int)(selfSprite.bounds.max.y - selfSprite.bounds.min.y);
_dynamicTexture = new Texture2D (width, height, TextureFormat.ARGB32, false);
DrawToTexture ();
}
private void Update(){
// This part is fully functionnal and was test with other texture
// assigned via the Unity developpement interface
renderer.sharedMaterial.SetTexture ("_ResultingTex", _dynamicTexture);
}
private void DrawToTexture(){
for(int x = 0; x < 64; x++) //hardcoded value for question purpose
{
for(int y = 0; y < 64; y++) //hardcoded value for question purpose
{
_dynamicTexture.SetPixel(x, y, _testColor);
}
}
}
}
The anticipated result should look like this:
Finally this is the Unity UI showing the before and after i run the test, just so you can view the whole thing(which is very simple in fact):