Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
アタッチしたオブジェクトの位置を、対象のカメラの左上・右下等に移動させる。上手く使うと子オブジェクトのx:0,y:0の座標を左上や右下に出来る
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