Scripting to switch Draw Halo on/off

Hi all,

really quick query, just want to know how to address the draw halo part of a light component. Effectively Im using them in my tank shooter game and I want to flick the halo on and off when a tank is hit by an enemy shell. I cant find the halo part of a light anywhere in the script reference so I thought i’d ask here first.

Thanks guys,

Will

If I recall correctly, there’s no way of doing this directly. One relatively simple solution would be to put it on a child GameObject and disable the entire child.

Arguably, the Halo component isn’t very useful because it can’t be scripted and it doesn’t have any way of taking an arbitrary shader. I usually end writing scripts to control billboards or emit single particles.

Indeed, well ive gone for a sphere with an alpha diffuse shader instead, does the same job!

Cheers!

To enable Draw Halo by script (tested on 2017.3), serialize the Light component then change the boolean value. SerializedObject halo = new SerializedObject(gameObject.GetComponent<Light>()); halo.FindProperty("m_DrawHalo").boolValue = true; halo.ApplyModifiedProperties();

This will not work in your builds - it’s editor only, hence why you also need “using UnityEditor;”.