Please use code formatting (the little button with 1s and 0s on it) when posting code. It doesn't always work correctly (IMX), but it will be better than what you have now. (You can edit your post and make this change.)
In any case, it looks like you have an errant semicolon after your 'if' statement. I'm not quite clear on what happens after that though. Is this your actual code? If so, does it compile, or are you getting compiler errors? (You can edit your original post to add additional information as needed.)
var Counter : int = 0;
function OnCollisionEnter (myCollision : Collision)
{
if(myCollision.gameObject.name == ("Cube"))
{
Counter++;
guiText.text : "Score: "+Counter;
}
}
Try that, your code was messy, so I believe I have put things in the right place. Give it ago
---EDIT---
Okay, for this, I would suggest making 2 scripts, 1 where all your GUI functions go, and another for the cube.
Script GUI:
function OnGUI(){
guiText.text : "Score: "+CubeScript.Counter;
}
CubeScript:
static var Counter : int = 0;
function OnCollisionEnter (myCollision : Collision)
{
if(myCollision.gameObject.name == ("Cube"))
{
Counter++;
}
}
Place the ScriptGUI into a game empty within your scene. For now on: Everything to do with your GUI should be placed within that script - makes everything really easy.
I've been having problems getting this to work for about a week.
Just wanted to say thanks Oliver, I'm now up and running.
@Jesse,
I don't know if it's required, but I also put a component/rendering/GUIText onto my ingame object that contains GUI stuff (my health meter [guitexture])
That let me type, pick font, size, and place it on screen where I wanted.
Olivers "score" showed in game instead of the text I wrote (a cuss word, lol), but in the same spot/font/etc..
(I think if you don't put the guiText on there you have to specify placement/font via script, not as easy IMO)