标题: RTS Style Camera Scrolling [打印本页] 作者: 晃晃 时间: 2011-11-16 17:25 标题: RTS Style Camera Scrolling
The Update function in the editor script in this example project has code for scrolling. Including the edge of the screen method, arrow keys, and middle mouse button method; pretty much all the RTS games I've played have at least the first two. Not including the public variables for scrolling speed and so on, the relevant code is:
var mPosX = Input.mousePosition.x;
var mPosY = Input.mousePosition.y;
// Do camera movement by mouse position
if (mPosX < scrollArea) {myTransform.Translate(Vector3.right * -scrollSpeed * Time.deltaTime);}
if (mPosX >= Screen.width-scrollArea) {myTransform.Translate(Vector3.right * scrollSpeed * Time.deltaTime);}
if (mPosY < scrollArea) {myTransform.Translate(Vector3.up * -scrollSpeed * Time.deltaTime);}
if (mPosY >= Screen.height-scrollArea) {myTransform.Translate(Vector3.up * scrollSpeed * Time.deltaTime);}