Search Unity

Need help with a bit of code :\

Discussion in 'Scripting' started by Anazoth, Aug 29, 2012.

  1. Anazoth

    Anazoth

    Joined:
    Apr 16, 2012
    Posts:
    38
    Hey everyone, i've been learning coding in unity lately and i'm stuck on a bit of code, i've tried everything to get it working and i just can't understand why it's not working. I am trying to make it so that when i hit an object with a rigidbody, it will emit a particle on the object when you hit it.

    I've run a debug and it says it's working, but my "spark" particle isn't showing up in the game. Can anyone tell me what i've done wrong?

    Code (csharp):
    1.  
    2. var hitParticle : ParticleEmitter;
    3.  
    4.        if(hit.rigidbody)
    5.         {
    6.             if( hitParticle )
    7.             {  
    8.             Debug.Log("particles is set");     
    9.                 hitParticle.transform.position = hit.point;
    10.                 hitParticle.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, hit.normal);
    11.                 hitParticle.Emit();
    12.            
    13.                 hit.rigidbody.AddForceAtPosition(directionRay * force, hit.point);
    14.                 hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    15.             }
    16.            
    17.         else{
    18.                 Debug.Log("particles not set");
    19.             }          
    20.         }
     
  2. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    is this just a snippet of code? is it inside an OnCollisionEnter or anything?
     
  3. ShadoX

    ShadoX

    Joined:
    Aug 25, 2010
    Posts:
    260
    just a wild guess, but any chance that you might be sending the particle in the wrong direction? so that it ends up going inside the object that you hit?