- Home /
Animating the Color.a on a Vertex Color Shader for iPhone
I wrote a script to change the alpha of a Vertex Color shader. It works fine in the editor, but doesn't fade to transparent on the iPhone (3Gs). I'm not sure if this is a technical limitation of the phone, or if I don't understand what I am doing again. Thanks in advance.
void Update(){
Color thisColor = textGO.GetComponent<MeshRenderer>().material.color;
thisColor.a -= .0025f;
textGO.GetComponent<MeshRenderer>().material.color = thisColor;
}
I am not familiar with iPhone coding but don't you need to fade the color with respect to time? thisColor.a -= rate * Time.deltaTime;?
Answer by BigToe · Dec 08, 2010 at 08:18 AM
I am not sure why it has started to work, but it seems fine now. I do realize I can access the GameObject this way instead:
textGO.renderer.material.color;
But it still is working the other way too.
Strange.
Please mark your own answer as correct (as soon as you have enough points).
Answer by cupsster · May 02, 2012 at 01:21 PM
untested code:
using UnityEngine;
using System.Collections;
public class FadeAway : MonoBehaviour {
public float targetAlphaValue = 0.0f; // target alpha value 0.0f to 1.0f
public float fadeTime = 1.75f; // time to fade to target alpha value
private Color startColor;
private Color targetColor;
private Color lerpedColor;
private Material objMaterial;
// Use this for initialization
void Start () {
objMaterial = gameObject.renderer.material;
startColor = objMaterial.color;
targetColor = new Color(startColor.r,startColor.g,startColor.b,targetAlphaValue);
}
// Update is called once per frame
void Update () {
lerpedColor = Color.Lerp(startColor, targetColor, fadeTime);
objMaterial.color = lerpedColor;
}
void ResetColor(){
objMaterial.color = startColor;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613090219im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Vertex colour shader with emissive multiplier 0 Answers
Shader Vertex Data Format 2 Answers
iPhone shader help to simulate TV static, works but not on iPhone. 1 Answer
Multiple Texture Colours 2 Answers