Why gameobject is not transparent on Android version?
I have racing game where opponent is transparent when he is close enough. There is codes: //Check how far other is and make ghost more transparent if close. float distance = Vector3.Distance(formulaMainPart.GetComponent().position, ghostMainPart.GetComponent().position);
distance *= 15;
if (distance >= 255)
{
if (!opaque)
{
opaque = true;
trasparent = false;
SetMaterialOpaque();
}
}
else
{
if (!trasparent)
{
trasparent = true;
opaque = false;
SetMaterialTransparent();
}
ghostMainPart.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
ghostTire1.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
ghostTire2.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
ghostTire3.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
ghostTire4.GetComponent<Renderer>().material.color = new Color32(255, 255, 255, (byte)distance);
}
private void SetMaterialTransparent()
{
foreach (Material m in ghostMainPart.GetComponent<Renderer>().materials)
{
m.SetFloat("_Mode", 2);
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
m.SetInt("_ZWrite", 0);
m.DisableKeyword("_ALPHATEST_ON");
m.EnableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = 3000;
}
foreach (Material m in ghostTire1.GetComponent<Renderer>().materials)
{
m.SetFloat("_Mode", 2);
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
m.SetInt("_ZWrite", 0);
m.DisableKeyword("_ALPHATEST_ON");
m.EnableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = 3000;
}
foreach (Material m in ghostTire2.GetComponent<Renderer>().materials)
{
m.SetFloat("_Mode", 2);
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
m.SetInt("_ZWrite", 0);
m.DisableKeyword("_ALPHATEST_ON");
m.EnableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = 3000;
}
foreach (Material m in ghostTire3.GetComponent<Renderer>().materials)
{
m.SetFloat("_Mode", 2);
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
m.SetInt("_ZWrite", 0);
m.DisableKeyword("_ALPHATEST_ON");
m.EnableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = 3000;
}
foreach (Material m in ghostTire4.GetComponent<Renderer>().materials)
{
m.SetFloat("_Mode", 2);
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
m.SetInt("_ZWrite", 0);
m.DisableKeyword("_ALPHATEST_ON");
m.EnableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = 3000;
}
}
private void SetMaterialOpaque()
{
foreach (Material m in ghostMainPart.GetComponent<Renderer>().materials)
{
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m.SetInt("_ZWrite", 1);
m.DisableKeyword("_ALPHATEST_ON");
m.DisableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = -1;
}
foreach (Material m in ghostTire1.GetComponent<Renderer>().materials)
{
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m.SetInt("_ZWrite", 1);
m.DisableKeyword("_ALPHATEST_ON");
m.DisableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = -1;
}
foreach (Material m in ghostTire2.GetComponent<Renderer>().materials)
{
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m.SetInt("_ZWrite", 1);
m.DisableKeyword("_ALPHATEST_ON");
m.DisableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = -1;
}
foreach (Material m in ghostTire3.GetComponent<Renderer>().materials)
{
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m.SetInt("_ZWrite", 1);
m.DisableKeyword("_ALPHATEST_ON");
m.DisableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = -1;
}
foreach (Material m in ghostTire4.GetComponent<Renderer>().materials)
{
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m.SetInt("_ZWrite", 1);
m.DisableKeyword("_ALPHATEST_ON");
m.DisableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = -1;
}
}
This is working fine in computer but when I use it on android phone it is not working. I can see that gameobject is transparent but alfa is not changing. Do someone know whats wrong with this. I tested that distance is same on android and pc but I think there might be something wrong with (byte) distance command.
Your answer
Follow this Question
Related Questions
Player Can't hit enemy 0 Answers
Get the lowest value from a Gameobject List 0 Answers
how to use vectors to control an outcome 0 Answers
Consistent spacing between gameobjects when some disabled 1 Answer