Last active
August 29, 2015 14:07
-
-
Save snaka/dcb90a145880fd79f0fe to your computer and use it in GitHub Desktop.
3Dのオブジェクトの表示位置に2DのUIオブジェクト追随させる ref: http://qiita.com/snaka/items/de1e86e62c447ea4971f
This file contains hidden or 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
GameObject obj3d; // 3Dオブジェクト | |
GameObject obj2d; // 2Dオブジェクト | |
Camera perspCamera; // 3Dオブジェクトを写すカメラ | |
Camera orthoCamera; // 2Dオブジェクトを写すカメラ | |
// 3Dオブジェクトのワールド座標から、Perspective カメラのビューポート座標を求める | |
var viewPortPos = perspCamera.WorldToViewPortPoint(obj3d.transform.position); | |
// 上記ビューポート座標を Orthographic カメラのワールド座標に逆変換する | |
var worldPos2d = orthoCamera.ViewportToWorldPoint(viewPortPos); | |
// 2Dオブジェクトの座標を移動 | |
obj2d.transform.position = worldPos2d; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment