상세 컨텐츠

본문 제목

Unity Drag Camera Movement

개발생활/Unity Engine

by 한국인맛집 2018. 10. 25. 13:22

본문

반응형
How to Drag & Drop Camera Position movement ?
public Vector2 dragOrigin;

void start(){
  
}



void update(){


if(Input.GetMouseButtonDown(0){
        dragOrigin = Input.mousePosition;
}



if(Input.GetMouseButton(0)) {
                if((transform.position.x > Constants.screenMinX && transform.position.x < Constants.screenMaxX) && (transform.position.y < Constants.screenMaxY && transform.position.y > Constants.screenMinY)) {
                    Vector3 mpos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
                      
                    Vector3 movent = -mpos * (Time.deltaTime * 2.0f);
                    Vector3 condition = transform.position + movent;

                    if((condition.x >= (Constants.screenMinX + 0.1f) && condition.x <= (Constants.screenMaxX - 0.1f)) && (condition.y >= (Constants.screenMinY + 0.1f) && condition.y <= (Constants.screenMaxY - 0.1f))) {
                        transform.Translate(movent, Space.World);
                    }
                }
            }

}



반응형

'개발생활 > Unity Engine' 카테고리의 다른 글

Unity3D Android Logcat  (0) 2019.01.18
Unity mouse Drag object/ Touch moved  (0) 2019.01.15
how to change script editor in Unity  (0) 2019.01.08
Unity RayCast 사용 ( 마우스 ) code  (0) 2018.10.25
Unity Screen rotation Fixed  (0) 2018.10.22
Unity Phone Screen Resolution Sizing  (0) 2018.10.22

관련글 더보기