All Projects → EvanHahn → Unity Rts Camera

EvanHahn / Unity Rts Camera

Licence: mit
A little script for RTS games in Unity. Abandoned. Add an issue if you want to take over!

RTS camera for Unity

Attach this script to a camera and then you can use it RTS-style.

Note: I'm a Unity newbie, so I'm sorry if I don't know what I'm doing! Happy to accept pull requests.

Quick start

  1. Attach this script to a camera.

  2. Add "Mouse Look" and "Mouse Select" to your inputs. I recommend changing the default Fire1 and Fire2 for left and right mouse buttons.

  3. Make sure selectable objects have 3D colliders on them.

  4. 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!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].