触れると落ちるブロックを作ろう




落ちるブロック
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallBlock : MonoBehaviour
{
// 変数の定義(データを入れる箱を作る)
private Rigidbody rb;
void Start()
{
// 代入(箱の中にデータを入れる)
rb = GetComponent<Rigidbody>();
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Player"))
{
// (ポイント)Invoke("呼び出すメソッド名", 呼び出すまでの時間)
// Fallという名前のメソッドを2秒後に呼び出して実行する。
Invoke("Fall", 2);
}
}
void Fall()
{
// (ポイント)isKinematicを無効化する
rb.isKinematic = false;
}
}





【2018版】BallGame(全25回)
他のコースを見る



落ちるブロック
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallBlock : MonoBehaviour
{
// 変数の定義(データを入れる箱を作る)
private Rigidbody rb;
void Start()
{
// 代入(箱の中にデータを入れる)
rb = GetComponent<Rigidbody>();
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Player"))
{
// (ポイント)Invoke("呼び出すメソッド名", 呼び出すまでの時間)
// Fallという名前のメソッドを2秒後に呼び出して実行する。
Invoke("Fall", 2);
}
}
void Fall()
{
// (ポイント)isKinematicを無効化する
rb.isKinematic = false;
}
}





触れると落ちるブロックを作ろう