Skip to content

Instantly share code, notes, and snippets.

@kankikuchi
Last active August 29, 2015 14:12
Show Gist options
  • Save kankikuchi/f1b5ac204ddea5e174d4 to your computer and use it in GitHub Desktop.
Save kankikuchi/f1b5ac204ddea5e174d4 to your computer and use it in GitHub Desktop.
特定のカメラに写ってるかの判定【Unity】
using UnityEngine;
using System.Collections;
public class IsRendered : MonoBehaviour {
//メインカメラに付いているタグ名
private const string MAIN_CAMERA_TAG_NAME = "MainCamera";
//カメラに表示されているか
private bool _isRendered = false;
private void Update () {
if(_isRendered){
Debug.Log ("カメラに映ってるよ!");
}
_isRendered = false;
}
//カメラに映ってる間に呼ばれる
private void OnWillRenderObject(){
//メインカメラに映った時だけ_isRenderedを有効に
if(Camera.current.tag == MAIN_CAMERA_TAG_NAME){
_isRendered = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment