パーティクルを動かす

もくじ
https://tera1707.com/entry/2022/02/06/144447

やりたいこと

パーティクル、いわゆるエフェクト?的な奴を出せるらしい。

出してみたい。

やりかた

  • ParticleSystem変数をpublicで定義する
public class PlayerController : MonoBehaviour
{
    private Rigidbody playerRb;
    public ParticleSystem explosionParticle;     //★コレ
    public ParticleSystem dirtParticle;          //★コレ
  • そいつにパーティクルのプレハブをinspectorで割り当てる

  • そいつをC#の中でPlay()する。
private void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Ground") && !gameOver)
    {
        isOnGround = true;
        dirtParticle.Play();        // ★コレ(スタート)
    }
    else if (collision.gameObject.CompareTag("Obstacle"))
    {
        Debug.Log("Game Over...");
        gameOver = true;
        playerAmin.SetBool("Death_b", true);
        playerAmin.SetInteger("DeathType_int", 1);
        explosionParticle.Play();
        playerAudio.PlayOneShot(crashSound, 1.0f);
        dirtParticle.Stop();       // ★コレ(ストップ)
    }
}