variable behavior on an object?

I’d like to have an object that responds one way the first time it’s clicked then a different way the second time it is clicked. Anyone know where I can find a similar script as a model to help me figure out how to write one of my own?
Also, are there any good scripting guides other than the one on the Unity site? I’d like something that has lots of scripts compiled together that I can print out and read over or refer to. How useful would a general text on Javascript be? Any good books out there to help with scripting in Unity?

var clicked : int = 0;

function OnMouseDown () {
    clicked++;
    if (clicked == 1) {
        print ("First click!");
    }
    else {
        print ("Not the first click!");
    }
}

I might use a boolean for that instead, but if you use an integer then you can modify it to check for other numbers if necessary.

I think a general Javascript book would be quite useful. Even though the web-specific stuff isn’t directly applicable, it still gives you an idea of how different programming concepts work.

–Eric

If you want a lot of examples you could go to the Unify Wiki Script archive. The Unify community is the unofficial Unity user community.

Thanks! I’ll play with that script and also see if I can find a good book. Anyone have any favorites? Something that can be handled by someone without much programming experience?
I had seen the Unify scripts page but haven’t had a chance to study them. I’ll look at them more soon.
Thanks to both of you.

There’s even more well written scripts the the example projects:

http://unity3d.com/examples/index.html

and in the documentation there’s a lot of little snippets:

http://unity3d.com/documentation.html

d.