오브젝트 카메라 프러스텀 안에 가두기
Unity3D/Script / 2013. 1. 29. 12:48
[사용 함수]
Camera.WorldToViewportPoint()
Camera.ViewportToWorldpoint()
1 public void pushObjectBackInFrustum(Transform obj) 2 { 3 Vector3 pos = Camera.main.WorldToViewportPoint(obj.position); 4 5 if(pos.x < 0f) 6 pos.x = 0f; 7 8 if(pos.x > 1f) 9 pos.x = 1f; 10 11 if(pos.y < 0f) 12 pos.y = 0f; 13 14 if(pos.y > 1f) 15 pos.y = 1f; 16 17 obj.position = Camera.main.ViewportToWorldPoint(pos); 18 }
참조 : http://forum.unity3d.com/threads/7069-Keeping-things-inside-the-camera-frustum
반응형
'Unity3D > Script' 카테고리의 다른 글
How to create an editor screenview like "camera preview" window for cameras? (0) | 2013.02.04 |
---|---|
마우스 휠 스크롤 확인 (0) | 2013.01.31 |
Using GUI slider to control animation on object (0) | 2013.01.27 |
InGame Button (0) | 2012.12.14 |
InvokeRepeating (0) | 2012.12.07 |