2D Toolkit Forum
2D Toolkit => Support => Topic started by: Dajuice on January 29, 2013, 10:39:11 pm
-
Hi there... beginning to be a little shy to take up all this time of yours, but I'm completely stuck.
I need to use one of your shaders on something that is not tk2d, then I need to change the color (trying to make some shadows...), I spelunked in your scripts and I think I found how you changed your colors, but then it does not seem to work. (it works with other shaders though)
here is the script (keep in mind it is testing script
using UnityEngine;
using System.Collections;
public class ShadowOnVaVoir : MonoBehaviour {
Color[] colors;
Color myColor;
void Awake() {
myColor = new Color(0, 0, 0, 0.5f);
Color[] colorsBegin = GetComponent<MeshFilter>().sharedMesh.colors;
colors = new Color[colorsBegin.Length];
GetComponent<MeshFilter>().sharedMesh.colors = colors;
}
void Update() {
renderer.material.SetColor("Color", myColor);
renderer.material.color = myColor;
int i = colors.Length;
while (i-->0) {
colors[i] = myColor;
}
}
}
As usual, thanks for your time and commitment
-
You need to reassign color after changing it in Update.
so after while(...) { }
do
sharedMesh.colors = colors;
That should be it I believe.
-
using UnityEngine;
using System.Collections;
public class ShadowOnVaVoir : MonoBehaviour {
Color[] colors;
Color myColor;
void Awake() {
myColor = new Color(0, 0, 0, 0.5f);
Color[] colorsBegin = GetComponent<MeshFilter>().sharedMesh.colors;
colors = new Color[colorsBegin.Length];
GetComponent<MeshFilter>().sharedMesh.colors = colors;
Debug.Log("yo");
Update();
}
void Update() {
renderer.material.SetColor("Color", myColor);
renderer.material.color = myColor;
int i = colors.Length;
while (i-- > 0) {
colors = myColor;
}
GetComponent<MeshFilter>().sharedMesh.colors = colors;
Debug.Log("hey");
}
}
... doesn't work, well I think I'll forget about it, it works on other shaders, it works with non RenderTextures, but there is no way to make it work for what I need ?L?.