LoginSignup
0
0

More than 3 years have passed since last update.

【Instantiate関数】当たったときに複製を生成する【テンプレスクリプト】

Last updated at Posted at 2021-01-20

下記スクリプトがアタッチされたオブジェクトは、
衝突判定時に、コンポーネントでアタッチされたオブジェクトを作成する。

  • アタッチするオブジェクトがパーティクルの場合は、パーティクルが都度生成される。
  • パーティクルの場合は、生成されたクローンがそのまま残ってしまうので、パーティクルシステム内のコンポーネントで、「Stop Action」を「Destroy」にすればよい。
particleSpawn.cs
using UnityEngine;

public class particleSpawn : MonoBehaviour
{
    public GameObject particle;

    private void OnCollisionEnter(Collision col)
    {
        Instantiate(particle.gameObject, this.transform.position, Quaternion.identity);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0