Apply a texture at startup js


Beginner here, I was just wondering if somebody knew a way to apply a specific material to a specific GameObject in javascript?

Specifically, I have a number of cubes, all with names, and a number of materials, also known by name. I want to set material 1 to cube 1, material 2 to cube 2 and so on…

Anybody know how to do this?

Also, how to get a specific material from the list of assets.

Please review the answer posted on this thread: Load Material to GameObject - Unity Answers

It should be what you are looking for, but you will need to edit the code for your specific needs.