How do I add shadows.

I have a simple cube.
My shadows dissapear after I add this code

newMat = Resources.Load("tiled", typeof(Material)) as Material;
cubed.GetComponent<Renderer>().material = newMat;
cubed.GetComponent<Renderer>().material.color = thecolor;

If I add it manualy in editor its got shadows. Whats the difference? I got no shadows.

Most likely you need to use Dynamic lighting and not prebake the shadows.

how do I do this with C# ? Thanks for answer.

oh I had to change my material legacy shader diffuse.