Highlight Selected Unit

I'm writing a game that has turn based party combat (similar to XCOM/Fallout 1&2, etc) and I would like to have a nice effect for indicating which unit is currently selected. I tried a 3d arrow above the object, its not really doing it for me so I'd like to have a "halo" or glow effect surround the model when its selected.

It looks like the right way to go is to manipulate the renderer off the object and set its alpha/texture mods? Is there a simple way to get this effect or will I need to use a second texture file here?

I'd prefer to do this programmatically if possible.

I'm going to reiterate and elaborate on the main points made in this similar answer. There are many ways to "highlight" an object, depending on the effect you want. Here are a handful of suggestions:

  • You could make use of the Glow effect (pro only). Glow only acts on objects whose renderer outputs an alpha value larger than zero to the colour buffer. This means, if you turn down the alpha value of every other object's mmaterial tint colour]2 to zero, and only turn up the alpha value of that particular object's material tint colour, only that object will Glow.

  • Without using the pro Glow effect, you could Adjust just the RGB values of the selected object's material tint colour. This allows you to tint the object any colour you like. Alternatively you could have all object's tint RGB set to 0.5,0.5,0.5 and then set the highlighted object material tint to 1,1,1 making it seem much brighter in comparison with the other objects.

  • You could creating a larger mesh which covers your object (perhaps procedurally positioned between the object and your camera), and give that a material with an additive shader, with a dull grey circle texture which fades to black at the edges. (Essentially a single large static 'particle'). The additive blending will make the object seem to glow.

  • You could create a mesh which has a transparent 'ring' texture, and place this on the ground at the same position as your selected object, giving a selection indicator which appears to be under your player at its base.

  • You could even use an animated particle effect at the same position as the object to give it a twinkling sparkly glowing effect.

Hope this gives you some inspiration!

Shader "Outlined Diffuse" 
{ 
   Properties 
   { 
      _Color ("Main Color", Color) = (.5,.5,.5,1) 
      _OutlineColor ("Outline Color", Color) = (0,1,0,1) 
      _Outline ("Outline width", Range (0.002, 0.03)) = 0.01 
      _MainTex ("Base (RGBA)", 2D) = "white" { } 
      //Not needed 
      //_ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } 
   } 

   SubShader 
   { 
      Tags {"Queue"="Transparent" "RenderType"="Transparent"} 

      //Minor switch 
      //UsePass "Toon/Basic/BASE" 

      CGPROGRAM
        #pragma surface surf Lambert

        sampler2D _MainTex;
        float4 _Color;

        struct Input {
            float2 uv_MainTex;
        };

        void surf (Input IN, inout SurfaceOutput o) {
            half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG

      Pass 
      { 
         Name "OUTLINE" 
         Tags { "LightMode" = "Always" } 

         Blend SrcAlpha OneMinusSrcAlpha

         CGPROGRAM 
#pragma exclude_renderers gles
#pragma exclude_renderers xbox360
         #pragma vertex vert 

         struct appdata { 
             float4 vertex; 
             float3 normal; 
         }; 

         struct v2f { 
            float4 pos : POSITION; 
            float4 color : COLOR; 
            float fog : FOGC; 
         }; 
         uniform float _Outline; 
         uniform float4 _OutlineColor; 

         v2f vert(appdata v) { 
            v2f o; 
            o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 
            float3 norm = mul ((float3x3)UNITY_MATRIX_MV, v.normal); 
            norm.x *= UNITY_MATRIX_P[0][0]; 
            norm.y *= UNITY_MATRIX_P[1][1]; 
            o.pos.xy += norm.xy * o.pos.z * _Outline; 

            o.fog = o.pos.z; 
            o.color = _OutlineColor; 
            return o; 
         } 

         ENDCG 

         Cull Front
         ZWrite On
         ColorMask RGBA
         Blend SrcAlpha OneMinusSrcAlpha
         //? -Note: I don't remember why I put a "?" here 
         SetTexture [_MainTex] { combine primary } 
      } 
   } 

   Fallback "Diffuse" 
}

should do the trick

I'm working on a similar project. In fact I'm currently designing the selection manager, but finding some difficulty choosing which method to go forward with. I've read some code people have written that uses raycasting, and the more simpler technique of mousedown functions on the objects themselves.

Might I ask which you found worked best for you? Old post, I know, but I'm hoping you might still be around.