Javascript : Preforming action based on physics material

Hello everybody

using javascript
I have a raycast script which instantiates effects on the object that the ray hits based on the tag on that object.

private var rayhit : RayCastHit;

if(rayhit.collider.tag == “Wood”)
{

do stuff ;

}

Is there a way I can replace the tag detection with physics material detection, so that I can have a few physics material for each for a type of surface that I need and when the raycast hits them it would instantiate the appropriate effect instead on using tags?

I am not sure if you can access the physics material via code, but you could just tag said item appropriately, based on its assigned material.

1 Like

That’s what he’s already doing; the idea is to not use tags. Anyway, yes, compare rayhit.collider.material to physics materials and do stuff based on the results.

–Eric

1 Like

Thanks for the help guys :slight_smile: