[UNITY]コライダーでゴールを作成する
[UNITY]コライダーでゴールを作成する

ゴールエリアのゲームオブジェクトを

ゴールエリアには

Create > Create Empty で空のゲームオブジェクトを

コライダーとレジットボディを

作ったゲームオブジェクトを


コライダーとリジッドボディの

BoxColliderとRigidbodyを以下のように

ゲームの中で動かす必要のあるコライダーの付いたオブジェクトは、リジッドボディを
キャラクターにコライダーとリジッドボディを追加

Hierarchyでキャラクターオブジェクトを


キャラクターのコライダーを

次に追加したCapusele Colliderの大きさを調整していきます。まず、Edit Colliderをクリックします。すると、Colliderがシーンウィンドウで

シーンウィンドウで赤矢印の
ゲームクリアの文字を

Hierarchyウィンドウで Create > UI > Text でUIテキストオブジェクトを追加します。


次にInspectorウィンドウで←のように

←のようにゲームウィンドウに「ゲームクリア」の文字が表示されました。

次にゴールエリアにキャラクターが来たことを発見するプログラムを作ります。まず、ProjectウィンドウでCreate > C# Scriptで新しいプログラムを作ります。作ったプログラムに下のプログラムをコーディングします。
※コードには

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
public GameObject MainText;
// Use this for initialization
void Start () {
MainText.SetActive (false);
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider collider){
Debug.Log ("OnTrriger1");
if (collider.gameObject.tag == "Player") {
Debug.Log ("OnTrriger");
MainText.SetActive (true); }
}
// 衝突している間呼ばれ続ける
void OnTriggerStay(Collider other) {
Debug.Log ("OnTrriger2");
}
// 衝突から離れた瞬間に呼ばれる
void OnTriggerExit(Collider other) {
Debug.Log ("OnTrriger3");
}
// 衝突した瞬間に呼ばれる
void OnCollisionEnter(Collision collision) {
Debug.Log ("OnColider1");
}
// 衝突している間呼ばれ続ける
void OnCollisionStay(Collision collision) {
Debug.Log ("OnColider2");
}
// 衝突から離れた瞬間に呼ばれる
void OnCollisionExit(Collision collision) {
Debug.Log ("OnColider3");
}
}