Created
July 10, 2014 18:24
-
-
Save tsubaki/3624c5c02390f4f457fc to your computer and use it in GitHub Desktop.
アタッチしたオブジェクトの位置を、対象のカメラの左上・右下等に移動させる。上手く使うと子オブジェクトのx:0,y:0の座標を左上や右下に出来る
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
using UnityEngine; | |
using System.Collections; | |
public class AncherLite : MonoBehaviour { | |
public Camera target; | |
public enum VIRTUCAL | |
{ | |
TOP = 10, | |
CENTER = 5, | |
BOTTOM = 0 | |
}; | |
public enum HOLIZONAL | |
{ | |
LEFT = 0, | |
CENTER = 5, | |
RIGHT = 10 | |
}; | |
public VIRTUCAL v; | |
public HOLIZONAL h; | |
void OnValidate() | |
{ | |
if( target == null) | |
target = Camera.main; | |
var z = transform.position.z; | |
var worldPoint = target.ViewportToWorldPoint(new Vector3(0.1f * (int)h, 0.1f * (int)v, z)); | |
worldPoint.z = z; | |
transform.position = worldPoint; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment