Switching between sprites

I am trying to change the image of a sprite.
I’m not trying to create a walking animation I’m just trying to change it periodically.
I would also like to change it after the game’s started.
I tried:

var costume:Sprite;
if(conditions){
    GetComponent(SpriteRenderer).sprite=costume;
}

It’ll run, but then when it should change it it disapears and I get an message saying it had an error casting from texture2d to sprite. I tried just adding (sprite) to the end, but I got an error saying It is not possible to invoke an expression of type ‘UnityEngine.Sprite’.
Help would be very much apreciated.

edit: the error in the first case is a pptr error if that helps

Hello, you probalby have wrong import settings for your sprite. Select your sprite in project and check if Texture Type is set to Sprite.

Check this for more info:
http://unity3d.com/learn/tutorials/modules/beginner/2d/sprite-type