Created
October 22, 2015 09:06
-
-
Save valbeat/7c3e7ee773a9447de779 to your computer and use it in GitHub Desktop.
Unityで真上からのカメラで位置のクランプ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Clamp() { | |
Vector3 posZToY = position; | |
posZToY.y = position.z; | |
Vector3 posInScreen = Camera.main.WorldToViewportPoint(posZToY); | |
Vector3 pos = position; | |
posInScreen.x = Mathf.Clamp (posInScreen.x, 0, 1); | |
posInScreen.y = Mathf.Clamp (posInScreen.y, 0, 1); | |
Vector3 _pos = Camera.main.ViewportToWorldPoint(posInScreen); | |
pos.x = _pos.x; | |
pos.z = _pos.y; | |
position = pos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment