- Home /
Invert The Color Of A GUIText Crosshair?
So, my problem is my GUIText "crosshair" (Placeholder for a real one) isn't very visible under normal circumstances, no matter what I change the color to. So I thought I would have the color of my crosshair to be the inverted color of what I look at, so as to be able to see the crosshair easily, like in the game Minecraft. If you don't get what I mean, here is the desired result:
I've tried this code, but it seems to always become black:
var Crosshair : GUIText;
function Start () {
}
function Update () {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
var dir : Vector3 = ray.direction;
if (Physics.Raycast (transform.position, dir, hit, 100))
{
Crosshair.color = hit.gameObject.renderer.material.color;
}else{
Crosshair.color = Color.black;
}
}
function InvertColor (color : Color) : Color {
return Color (1.0-color.r, 1.0-color.g, 1.0-color.b);
}
Comment
Wiki
Answer by Pendrokar · Sep 23, 2014 at 03:49 PM
See the answer of: http://answers.unity3d.com/questions/292381/invert-filter-reticule.html