Skip to content

Instantly share code, notes, and snippets.

@nakamura001
Created August 27, 2012 11:59
Show Gist options
  • Save nakamura001/3487838 to your computer and use it in GitHub Desktop.
Save nakamura001/3487838 to your computer and use it in GitHub Desktop.
[Unity]テキストのRect情報取得
using UnityEngine;
using System.Collections;
public class TestGUI : MonoBehaviour {
private string txt = "test";
public GUIText guiText;
public GUIText guiTextInfo;
public GUITexture guiTextureBg;
void OnGUI () {
txt = GUI.TextField(new Rect(5, 5, 200, 20), txt);
guiText.text = txt;
guiTextInfo.text = guiText.GetScreenRect().ToString();
Rect rcGuiText = guiText.GetScreenRect();
Rect rc = rcGuiText;
rc.x += -Screen.width*.5f;
rc.y -= Screen.height*.5f;
guiTextureBg.pixelInset = rc;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment