How to add Particles, audio, material in runtime by JS code?

I used the following code to add rigidbody and collider to a gameobject in runtime.

var l_palm = GameObject.Find("Player/man/Pelvis/Spine/Spine.2/Heart/L_Shoulder/L_Elbow/L_Hand/L_Palm");
var collider_l_palm = l_palm.AddComponent(SphereCollider);
var rigidbody_l_palm = l_palm.AddComponent(Rigidbody);

Now, I need to add Particles, audio, material to the same gameobject when collide.

function OnCollisionEnter(hit : Collision)
{
	if(hit.gameObject.tag == "lightpunch")
	{
		Character.animation.Play ("beingattack"); 
                //how to add particles, audio, material here?
	}
}

here is the components that i need to add and how should I access them to set their properties?

The easiest way to do this is to set up the particle effect and sound on an empty GameObject in the scene and then make a prefab from it. You can then instantiate the prefab wherever you want to release the particles. In your code, you would probably use something like this:-

var effectPrefab: GameObject;

function OnCollisionEnter(hit : Collision) 
{ 
   if(hit.gameObject.tag == "lightpunch") 
   { 
      Character.animation.Play ("beingattack"); 
      Instantiate(effectPrefab, hit.contacts[0].position, Quaternion.identity);
   } 
}

If you enable the One Shot and Autodestruct options on the particle system, the effect object will be destroyed when the last particle has disappeared.

I changed the code:

var particlePunch : GameObject;
function OnCollisionEnter(hit : Collision)
{
Instantiate (particlePunch, hit.contacts[0].position, Quaternion.identity);	
}

Error:
‘position’ is not a member of ‘UnityEngine.ContactPoint’.

Try:

Instantiate (particlePunch, hit.contacts[0].transform.position, Quaternion.identity);

error:

‘transform’ is not a member of ‘UnityEngine.ContactPoint’.

Debug.Log your contact(0)…

I really dont think you need it…so delete contact(0) since your just trying instantiate at the hit position.

Instantiate (particlePunch, hit.transform.position, Quaternion.identity);

or

Instantiate (particlePunch, hit.gameObject.transform.position, Quaternion.identity);

or you might not even need the hit in that script and use the contact(0):

Instantiate (particlePunch, contact(0).transform.position, Quaternion.identity);

There might be syntax errors but try them all to see if u get results.

Sorry, made a mistake there. The field is not called position, but point. The code should look like this:-

Instantiate (particlePunch, hit.contacts[0].point, Quaternion.identity);

It’s always worth checking the manual out when you get one of those “not a member” errors.