纳金网

标题: 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);}
         

           // Do camera movement by keyboard
           

           myTransform.Translate(Vector3(Input.GetAxis("EditorHorizontal") * scrollSpeed * Time.deltaTime,Input.GetAxis("EditorVertical") * scrollSpeed * Time.deltaTime, 0) );
           



           // Do camera movement by holding down option or middle mouse button and then moving mouse
           

           if ( (Input.GetKey("left alt") || Input.GetKey("right alt")) || Input.GetMouseButton(2) ) {
           



           myTransform.Translate(-Vector3(Input.GetAxis("Mouse X")*dragSpeed, Input.GetAxis("Mouse Y")*dragSpeed, 0) );
           

           }
         

作者: 菜刀吻电线    时间: 2013-2-14 23:28
不错 非常经典  实用

作者: 奇    时间: 2013-3-12 23:30
很有心,部分已收录自用,谢谢

作者: nts    时间: 2013-10-17 10:38
不太能看懂,但觉得很强大




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5