I’m trying to make an iOS version of something I already had up and running for PC/Mac. In the desktop version, a big part of my game’s aesthetic was my ability to change objects’ materials’ alpha value via scripting. However, with Unity iOS, it seems like changing renderer.material.color.a does nothing.
i’ve tried using both mobile and standard transparent shaders (if this isn’t what you mean, please let me know what you’re talking about), but neither seem to respond to changing the renderer.material.color.a variable while the game is running. changing said variable totally worked on my desktop version, though.
to be clear: my objects are semi-transparent when the game starts in accordance to the main color’s alpha as set in the inspector prior to pressing Play. i can’t change it with scripting while the game is running, though.
edit: changing renderer.material.color isn’t always working correctly either. really confusing why it’d be working in some spots and not in others.
Put up a tiny package that illustrates the problem. There’s nothing inherently broken about what you’re talking about. The first thing that comes to mind is that you have the things set to be static, which has given me unpredictable results sometimes, as to what can be modified about a mesh or material.
i did have my objects as static, but i changed them to dynamic and got no different results. i’ve also tried attaching a light to my objects and that isn’t working either. here’s my code:
function Update(){
if (Input.GetMouseButtonDown(0)) { //moved from OnMouseDown override
current_cam = mainscript.current_cam;
var ray = current_cam.ScreenPointToRay(Input.mousePosition);
if (mainscript.edit_mode Physics.Raycast(ray, hit, 100) hit.transform == transform) {
q = !q;
if (!q) {
naturalColor = Color.grey;
renderer.material.color = naturalColor;
naturalColor.a = 0.5;
mainscript.qArray[beat]--;
} else {
naturalColor = lightColor;
naturalColor.a = 0.7;
mainscript.qArray[beat]++;
Debug.Log(mainscript.qArray[beat]);
}
renderer.material.color = naturalColor;
}
}
if (light.enabled) {
light.range -= 0.1;
if (light.range < 0) {
light.enabled = false;
}
}
}
function FixedUpdate() {
if (dimOnNext) {
renderer.material.color = naturalColor;
dimOnNext = false;
}
}
function lightAndPlay() {
audio.Play();
renderer.material.color = Color.white;
renderer.material.color.a = 1;
light.enabled = true;
light.intensity = 8;
light.range = 10;
dimOnNext = true;
}
the lights aren’t doing anything at all, visually. in the editor viewport, i can see the range changing as it should.
the materials’ alpha won’t change in any case and, in the lightAndPlay function, the color won’t change. however, the color-changing bit of code in the update override works perfectly.
edit: my timestep is large, so don’t think things are changing and then getting switched back quickly in FixedUpdate. also, lightAndPlay is called from outside this code.
so, i changed the FixedUpdate override in another script into a function that gets called according to comparing Time.time to a timekeeping variable in Update…and material changes are working now.