I try to do this by myMaterial = Instantiate("MaterialName") and myMaterial = new MaterialName() But without any success.
I'm a novice and can't yet clear understand the poject panel paradigm. Can I access to objects in it? This objects, it`s classes or instances?
The project pane represents files on your computer, which have been placed in the 'Assets' folder of your project. These are files which are ready for use in your scene, but which may or may not have been used yet.
With normal use in Unity, you generally don't access these by name from script. Instead you drag references from your project view to various target destinations. You might drag a material directly on to an object in your scene (represented either in the scene view, or the hierarchy pane).
Or if you want to refer to a particular material in a script, you could create a public variable of type 'Material' in your script. This would expose the material variable for that script in the inspector, and you can then drag the material into that slot.
However, if you are placing a script on a GameObject which is visible in the scene, the chances are that object already has a material. You can refer to the material of the object on which the script is placed by using renderer.material like this:
Notice (as described in the docs) that accessing the object's material like this will actually create a temporary runtime clone of the material (thus making it unique to that object, even if it was initially shared by many objects in your scene). To affect all models which share a material use renderer.sharedMaterial like this instead:
hope this helps!
answered Dec 14 '09 at 04:19 PM