Created
February 3, 2015 20:30
-
-
Save kankikuchi/d5e0662dfbe80700e438 to your computer and use it in GitHub Desktop.
画面外の当たり判定を消す【Unity】
This file contains hidden or 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 IsRendered : MonoBehaviour { | |
| //メインカメラに付いているタグ名 | |
| private const string MAIN_CAMERA_TAG_NAME = "MainCamera"; | |
| //カメラに表示されているか | |
| private bool _isRendered = false; | |
| private void Update () { | |
| if(_isRendered){ | |
| Debug.Log ("カメラに映ってるよ"); | |
| } | |
| else{ | |
| Debug.Log ("カメラに映っていないよ"); | |
| } | |
| //カメラに写っていれば当り判定有効 | |
| if(GetComponent<Collider> ()){ | |
| GetComponent<Collider> ().enabled = _isRendered; | |
| } | |
| if(GetComponent<Collider2D> ()){ | |
| GetComponent<Collider2D> ().enabled = _isRendered; | |
| } | |
| _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