1)スクリプの準備
・C#スクリプトを1つ作成→名前を「InvisibleBox」に変更
・下記のコードを記載する。
using UnityEngine;
using System.Collections;
public class InvisibleBox : MonoBehaviour {
// ①変数の定義(データを入れるための箱を作る)
private MeshRenderer mesh;
void Start(){
// ②代入(箱の中にデータを入れる)
mesh = GetComponent<MeshRenderer>();
}
void OnCollisionEnter(Collision other){
if(other.gameObject.CompareTag("Player")){
// ③データの入った箱を活用する
mesh.enabled = true;
}
}
}
2)Unityの設定
①作成した「InvisibleBox」スクリプトをドラッグ&ドロップする。
②「Inspector」で「Mesh Renderer」のチェックを外す。
・チェックを外すと透明な状態になります。
このチェックを外した状態を「enabled = false」と言います。

