いただいていたデータから派生していきます

衝突の検知で破壊される床を作ります

  1. Planeの作成: Hierarchyウィンドウから3D Objectを選び、Planeを生成します。
  2. Destroyerスクリプトの作成: PlaneにDestroyerスクリプトを追加します。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    // クローンを生成する対象プレハブアセット 
    [SerializeField] GameObject spawnTarget;


    // Start is called before the first frame update 
    void Start()
    {

    }

    // Update is called once per frame 
    void Update()
    {


    void OnCollisionEnter(Collision collision)
    { 
            Destroy(collision.gameObject);
            //故リジョンには衝突した相手は誰どこなどの情報が入っている)

        // スペースキーを押したら 
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // クローンを生成 
            Instantiate(
                    spawnTarget,            // 生成する対象 
                    transform.position,     // 生成時の座標 
                    Quaternion.identity     // 生成時の角度 
                );
        }

    }
}

これがいただいていたものです

ここからDestroyerのスクリプトを書き込んでいきます

お互いColliderを持ったうえでぶつかるから衝突が起きます。

両方がリジットボディを持たせることを忘れているひとが多いです

Assets/Spawner

コリジョンエンターとトリガー系があり6判定のあたり判定がある

  1. Planeの作成: Hierarchyウィンドウから3D Objectを選び、Planeを生成します。
  2. Destroyerスクリプトの作成: PlaneにDestroyerスクリプトを追加します。

C#のAssets/Spawnerとデストロイヤ―を混ぜて書いていたので

最初errorバリバリでしたが別々に書いてOK

でここの②の作業、

え?ッッ

ScriptのPlane追加ができてないだけでしたっ

(これを言いたくてBlogに記事を書いたといってもいい(;´Д`))

よかった誰も聞いてないのに4回目に質問したら恥でしょうw

ということでインスペクターWindowsにD&Dで見事に

当たり判定でいなくなる球体を再現することができましたーー

これが今回のコードです

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Destroyer : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // 他のcolliderに触れた時に呼び出される 引数は衝突情報
    void OnCollisionEnter(Collision collision)
    {
        // 衝突した相手ゲームオブジェクトを破棄する
        Destroy(collision.gameObject);
    }
}

Share this content:

By Air

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA