Search Unity

particle collision with cube

Discussion in 'Editor & General Support' started by Ester, Mar 2, 2010.

  1. Ester

    Ester

    Joined:
    Mar 2, 2010
    Posts:
    4
    Hello!

    For a school assignment I'm working on a game in Unity but I'm having some problems.
    I want that when a cube (rigid) collides with particles there starts a sound.
    Now I have the collision between the cube and the particles but I can't find how to let it start playing a sound when the collision happens.

    Can annyone help me?
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Hi, welcome to the forum!

    Presumably, you've already got the world particle collider component for the particle system. You just need to add an OnParticleCollision function to the cube's script and play the sound from there.
     
  3. Ester

    Ester

    Joined:
    Mar 2, 2010
    Posts:
    4
    thanks it worked! :D
     
  4. Ester

    Ester

    Joined:
    Mar 2, 2010
    Posts:
    4
    I got another small question.
    I just want in my script that when y is bigger then 70 that then it will play the sound but I don't know how to script that.

    I now have:


    function OnParticleCollision (other : GameObject) {
    print("particle bots in de particle");
    if (y < 70){
    print ("y getal werkt")
    var body = other.rigidbody;
    audio.Play();
    if (body) {
    print ("het is een rigidbody");

    }
    }
     
  5. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The main problem is that < is actually the "less than" symbol - you need to use > instead.
     
  6. Ester

    Ester

    Joined:
    Mar 2, 2010
    Posts:
    4
    yeah I saw that :p woops :p I figured it out it works now :D thanks for your help