Hello,
the following code doesn’t work similar on pc and adroid. This file just has to be stored as CircleTest.cs in Unity and attached to the main camera. Then it should draw a little red circle on center of screen and this works on windows in editor (also when i have switched to android as platform). But on a real android device it completely ignores the defined color → it just draw a black circle.
Maybe it has something to do with the generated shader, but anyway i dont understand what the problem is. I hope someone can help me!
Thx in advance!
Dataworm
`
using UnityEngine;
using System.Collections;
public class CircleTest : MonoBehaviour {
private Material triangleMaterial;
public Color circleColor = Color.red;
public int numberOfTriangles = 30;
Camera cam;
float nearClip;
void Awake () {
triangleMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass {" +
" BindChannels { Bind \"Color\",color }" +
" Blend SrcAlpha OneMinusSrcAlpha" +
" ZWrite Off Cull Off Fog { Mode Off }" +
"} } }");
triangleMaterial.hideFlags = HideFlags.HideAndDontSave;
triangleMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
void Start () {
cam = camera;
nearClip = cam.nearClipPlane+0.01f;
}
void OnPostRender () {
drawCircle(new Vector2(Screen.width/2, Screen.height/2),50);
}
private void drawCircle(Vector2 position, float size) {
float value = 200f;
float originX = position.x;
float originY = Screen.height - position.y;
float r = size/2;
GL.PushMatrix();
triangleMaterial.SetPass(0);
GL.Begin(GL.TRIANGLES);
GL.Color(circleColor);
Vector3 p;
float step = 360/numberOfTriangles;
float i=0f;
while(i<360f) {
p = new Vector3(r * Mathf.Cos((90-i)*Mathf.Deg2Rad) + originX, r * Mathf.Sin((90-i)*Mathf.Deg2Rad) + originY, nearClip);
GL.Vertex(cam.ScreenToWorldPoint(p));
i += step;
p = new Vector3(r * Mathf.Cos((90-i)*Mathf.Deg2Rad) + originX, r * Mathf.Sin((90-i)*Mathf.Deg2Rad) + originY, nearClip);
GL.Vertex(cam.ScreenToWorldPoint(p));
p = new Vector3(originX, originY, nearClip);
GL.Vertex(cam.ScreenToWorldPoint(p));
}
GL.End();
GL.PopMatrix();
}
}
`