Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created April 26, 2016 14:53
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/6a0896ac17fcc2463ceca687b7547c07 to your computer and use it in GitHub Desktop.
Save tsubaki/6a0896ac17fcc2463ceca687b7547c07 to your computer and use it in GitHub Desktop.
画面外と中を判定するやつ
using UnityEngine;
using UnityEngine.UI;
public class InOutTest : MonoBehaviour {
[SerializeField] Transform target;
[SerializeField] Camera targetCamera;
[SerializeField] Text text;
private Rect rect = new Rect(0, 0, 1, 1);
void Update ()
{
var viewport = targetCamera.WorldToViewportPoint(target.position);
text.text = rect.Contains(viewport) ? "IN" : "OUT";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment