RTS-style selection circle/marquee

How do I go about doing a selection circle, like in many RTS games, when I select a game-object? I believe it is to take a texture of a 2D circle, assign it to a flatten gameobject, and position it such that it will be at the center of the object.

  1. How do I find the size of an existing object?
  2. Is there any definite way to get the center location of a object, despite its pivot? This is because different game-objects may have different pivot points.
  3. If I am using terrain, how do I make it such that the texture maps to the terrain, if therre are slopes?

Samples are appreciated if they exist on the Internet.

For questions 1) and 2), you could use renderer.bounds.

If you're using terrain, and you want your selection circle to paint on the terrain underneath the object, you need to use a Projector.

They can be a little tricky to set up, having the correct art assets for the cookie as well as the selection texture, but if you get it setup right, it should do exactly what you want.

There's a projector example in the Standard Assets folder that comes with Unity. You should check it out and learn how it works, then try to implement your own in your game.

For #3, you may want to see the Unite '09 conference on shader tricks. The demonstrated expansion of color in Puzzle Bloom might be appropriate for what you want, although you may need to project an object on top of your terrain.