Physic material to var?

Searched around can’t findy. I know how to make a new physic material in script but how bout assign one i made in the inspector to a var in script? :face_with_spiral_eyes:

var myMaterial : PhysicMaterial;

–Eric

Thanks, I was wondering this too! :slight_smile:

But how do you assign that variable? myMaterial = MyIce?

Drag’n’drop, like any other public variable that references objects (i.e., “var go : GameObject;”).

–Eric

Sorry I still don’t understand your answer. Drag my physicmaterial from the editor onto my script? Its not droping anything. :frowning:

You need to attach the script to a game object, then click the little arrow next to the myMaterial text the select your material…

Ok I see, but can you assign the material at runtime without the editor via script?

public var myMaterial : PhysicsMaterial = Resources.Load("/materials/myMaterial"); (JS)
public PhysicsMaterial myMaterial = Resources.Load("/materials/myMaterial"); (C#)

Make sure you have a folder in project named Resources, put your material in there, in a folder called materials.

Assets/Resources/materials/myMaterial

Thanks. I dont suppose anyone knows why the above resets the friction values? I’m using below code:

//MyIce is a physic material I made in the editor with 0 in every entry
var mymat : PhysicMaterial = Resources.Load("/materials/MyIce",PhysicMaterial)
//BUT i get .4 printed from below code instead of 0
var colliderx = GameObject.Find("track 1").AddComponent (MeshCollider);
colliderx.material = mymat;
print (colliderx.material.dynamicFriction);

i know i can reassign the friction but I’d like to sort this out.

Love your sig, it’s awesome LoL

Hahah thanks man!

Mabye?

Yeah i know i can assign the friction but I shouldn’t have to since I did when I made the physicmaterial. I think this is a bug. I did find a way around this. For some reason I had to use Resources.Load(“myMaterial”,PhysicMaterial); with myMaterial in the resource folder. I dont know why it didnt load from the materials folder.

Thanks for the help.