Adding Material Via script

This should be an easy one but I’m pretty new to scripting. I’ve created several materials in unity. I’m trying to add a material to a game object ( its a initiated prefab) via scrip. At some point I want a different material randomly add to each instance. But for now, I’m just trying to get it to work with one material. Here is my script thus far:

#pragma strict

function Update ()

{

	Material.GameObject.Find(Laser_Blue01);
	
}

This gives me the following errors:
Assets/Scripts/laserColor.js(7,18): BCE0019: ‘GameObject’ is not a member of ‘UnityEngine.Material’.
Assets/Scripts/laserColor.js(7,34): BCE0005: Unknown identifier: ‘Laser_Blue01’.

Anyone have any ideas?

The smiley is suppose to be “1 8 )” lol

So I was able to get it kind of work using:

#pragma strict

function Update ()

{
	var material : Material;
	renderer.material.shader = Shader.Find ("Laser_Blue01");
	
}

The problem is, is that no matter what material I use (Laser_Blue01, Laser_Yellow01… and so on) the laser color is pink. Any ideas?

var myMaterial : Material;  // assign in inspector

function Start () {
    renderer.material = myMaterial;
}
var myMaterials : Material[];  // assign in inspector

function Start () {
    renderer.material = myMaterials[Random.Range(0, myMaterials.Length)];
}

–Eric

Fantastic!!! Thank you for your help :slight_smile: