What’s the best way to highlight an object to indicate it’s been selected? For example, the user clicks an object to select it, then clicks a location to move it to.
Ideally, I’d like to just change its color, like giving it a tint. But that doesn’t work when more than one object shares the same material. They all get colored.
A halo would work too (and look kind of cool). But I can’t find any way to turn the halos on different objects on and off from a script.
In an application developed at work, we had objects build a slightly enlarged (to prevent intersection artifacts) bounding box around its mesh when selected. The bounding box was given a baby-blue transparent material so it looked like it was highlighted. That might be one hack of an option for you. Though our objects were fairly rectilinear so the bounding box fit nicely; I don’t know if yours are.
EDIT: here’s a screenshot of what we have. The blue highlights are actually separate translucent bounding boxes generated on the fly.
I don’t understand this. What light component? Is it attached to the camera or the object with the halo? Other than a scene light, I have no light component attached to anything.
I’m also confused about the camera having a halo layer. It doesn’t seem to matter if it has one or not. I have an object that I attached a halo component to. That halo shows whether or not the camera has a halo layer. That halo is also not affected by the halo strength render setting. The only way I can turn the halo off is by unchecking its box in the inspector.
I’m trying this with the simplest possible scene – one camera, one light, and one object with a halo. The object with a halo also has a particle emitter.
Yes i was suggesting that you add a light component to your object. Then enable and disable the light with The OnMouseEnter Exit functions. If you have the halo box checked then it will stay checked. Then adjust the range of the light. The halo will pretty much just illuminate the obejct itself. all you need to do is add the script example to the object that has a collider and a light component.
Anyway check out this little script i threw together with some forum examples as inspiration.
//@@@//==HOVER OVER COLOR CHANGE==//@@@//
var colorItRed : boolean;
var colorItBlack : boolean;
var colorItBlue : boolean;
var colorItGreen : boolean;
var colorItYellow : boolean;
var colorItWhite : boolean;
var highlight : boolean;
var alpha : boolean;
var highlightMultiply : float;//Good at 1.5
var alphaMultiply : float;//0.0 to 1.0
private var originalColor;//Good example of how to set the var on start.
//===================================================================================//
function Start() {
originalColor = renderer.material.color;
}
//===================================================================================//
function OnMouseOver() {
if(highlight) {
renderer.material.color.r = originalColor.r*highlightMultiply;
renderer.material.color.g = originalColor.g*highlightMultiply;
renderer.material.color.b = originalColor.b*highlightMultiply;
renderer.material.color.b = renderer.material.color.b*highlightMultiply;
}
if(alpha) {
renderer.material.color.b = renderer.material.color.a = alphaMultiply;
}
if(colorItRed) {
renderer.material.color = Color.red;
}
if(colorItBlack) {
renderer.material.color = Color.black;
}
if(colorItBlue) {
renderer.material.color = Color.blue;
}
if(colorItGreen) {
renderer.material.color = Color.green;
}
if(colorItYellow) {
renderer.material.color = Color.yellow;
}
if(colorItWhite) {
renderer.material.color = Color.white;
}
}
//===================================================================================//
function OnMouseExit() {
yield new WaitForSeconds(0.1);
if(highlight) {
renderer.material.color.r = originalColor.r*highlightMultiply;// Set color back to original
renderer.material.color.g = originalColor.g*highlightMultiply;
renderer.material.color.b = originalColor.b*highlightMultiply;
renderer.material.color.b = renderer.material.color.b/highlightMultiply;
renderer.material.color = originalColor;
}
renderer.material.color = originalColor;
}
Another possibility would be to create a new layer “Highlight” and one or more directional lights (maybe colored) which illuminate only that layer (culling mask).
Then all you have to do is to put the selected objects on the “Highlight” layer.
I’ve already got a method of highlighting worked out. Thanks.
This has become a totally separate, although related, issue. I have a bunch of objects that when they get within a certain distance of each other, I want to put a glow around them. The halo effect is exactly what I want. But I need to be able to turn it off and on. I’ve tried adding a light, as suggested, but can’t get that to work. The halo is always on.