RTS camera for Unity
Attach this script to a camera and then you can use it RTS-style.
Note:This is a updated version of the script by EvanHahn. For Unity 5
Quick start
-
Attach this script to a camera.
-
Add "Mouse Look" and "Mouse Select" to your inputs. I recommend changing the default Fire1 and Fire2 for left and right mouse buttons.
-
Make sure selectable objects have 3D colliders on them.
-
For any selectable object, add the following code:
void OnTriggerEnter(Collider other) { if (other.gameObject.name == "RTS Selection") { // This object has been selected; do stuff! } } void OnTriggerExit(Collider other) { if (other.gameObject.name == "RTS Selection") { // This object has been deselected; do stuff! } }
That's it!
For more usage, check out the demo.
Class RTSCamera
One RTSCamera should be attached to the main camera for your game.
Property | Type | Default | Description |
---|---|---|---|
disablePanning |
bool |
false |
When true, the player cannot pan the camera. |
disableSelect |
bool |
false |
When true, the player cannot select. |
disableZoom |
bool |
false |
When true, the player cannot zoom. |
selectColor |
Color |
Color.green |
The selection box drawn on-screen will be this color. |
selectLineWidth |
float |
2f |
The selection box drawn on-screen will have this line width. |
maximumZoom |
float |
1f |
Maximum zoom; minimum camera scale. (This value will be less than minimumZoom , which might seem backwards.) |
minimumZoom |
float |
20f |
Minimum zoom; maximum camera scale. (This value will be greater than maximumZoom , which might seem backwards.) |
lookDamper |
float |
5f |
Panning speed will be divided by this value. A higher number makes for slower panning. |
selectionObjectName |
string |
"RTS Selection" |
When a selection happens, a trigger (a BoxCollider) will be dropped briefly into the scene. It will have this name. |
Enjoy!