Mouse over issues

I have this script so far

function OnMouseEnter ()

{
	renderer.material.mainTexture = "Assest/Materials/Lightning Mat.mat";
}

function OnMouseExit ()

{
	renderer.material.color = Color.white;
}

What i’m trying to achieve is that when i mouse over and object it uses my material to produce an effect from the object itself but when i mouse over i get this error.

InvalidCastException: Cannot cast from source type to destination type.

I’m a little confused as to what it means, any help :)?

you did write ‘Assest’, maybe that is the point…

if i use the texture from the inspector - it work…

var texture : Texture;
function OnMouseEnter ()
{
	renderer.material.mainTexture = texture;
}

function OnMouseExit ()
{
	renderer.material.mainTexture = null;
}

also look at the 2nd example of the following link because of shader/material/color…
http://unity3d.com/support/documentation/ScriptReference/Material.Material.html

Your doing some weird stuff. firstly the name of the resource you are wanting to load implies a material which you are setting in to a texture. Secondly the reason you are getting the cast error message is that you are trying to assign a STRING in to a TEXTURE.

To load an asset from your resource folder use resource.load

renderer.material.mainTexture = Resources.Load(“texturename”);

Thanks for the replies, yeah i was doing stuff weird as i was attempting to try theories of how i could write the script but failed hard it seems :stuck_out_tongue: i’ve been working with scripting for a little while but still suck and have a lot to learn

Thanks again for the replies i think i should be able to get something working now :slight_smile: