Created
March 17, 2014 16:40
-
-
Save tsubaki/9603045 to your computer and use it in GitHub Desktop.
maincameraから見た左上・右下等にゲームオブジェクトを移動する。左上を(0,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 EasyAnchor : MonoBehaviour | |
{ | |
public enum VerticalPosition | |
{ | |
Top = 2, | |
Center = 1, | |
Bottom = 0 | |
} | |
public enum HorizontalPosition | |
{ | |
Left = 0, | |
Center = 1, | |
Right = 2 | |
} | |
public VerticalPosition vertical; | |
public HorizontalPosition horizonal; | |
[ContextMenu("Anchor")] | |
void MoveAnchor () | |
{ | |
float v = (float)vertical / 2; | |
float h = (float)horizonal / 2; | |
Vector3 pos = Camera.main.ViewportToWorldPoint (new Vector3 (h, v, -Camera.main.transform.position.z)); | |
transform.position = pos; | |
} | |
void OnValidate () | |
{ | |
MoveAnchor (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment