Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created July 10, 2014 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/3624c5c02390f4f457fc to your computer and use it in GitHub Desktop.
Save tsubaki/3624c5c02390f4f457fc to your computer and use it in GitHub Desktop.
アタッチしたオブジェクトの位置を、対象のカメラの左上・右下等に移動させる。上手く使うと子オブジェクトの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