Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question need help collisionEvents ?

Discussion in 'Physics' started by Julius22, May 1, 2023.

  1. Julius22

    Julius22

    Joined:
    Oct 2, 2022
    Posts:
    2
    I use a particle system for a rain effect. What I want is when a single particle collides with my floor, a good effect spawns at the position. I attached this script to the floor.
    numCollisionEvents is always 0. I have no idea what is going on. oh..!





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

    public class rainEffect_floor : MonoBehaviour
    {
    public GameObject effect;
    public ParticleSystem ps;
    public List<ParticleCollisionEvent> collisionEvents;

    void Start()
    {
    collisionEvents = new List<ParticleCollisionEvent>();

    }

    void OnParticleCollision(GameObject other)
    {



    int numCollisionEvents = ps.GetCollisionEvents(other, collisionEvents);
    Debug.Log(numCollisionEvents);

    for (int i = 0; i < numCollisionEvents; i++)
    {

    Instantiate(effect, collisionEvents.intersection, Quaternion.identity);
    }
    }
    }
     
  2. Julius22

    Julius22

    Joined:
    Oct 2, 2022
    Posts:
    2
    I.. really need some help. Cause my brain doesn't work
     
  3. berkcanhasanaydin

    berkcanhasanaydin

    Joined:
    Jan 29, 2020
    Posts:
    2
    Did u check collision and also send collision messages under it in particle system?