What can i do make this work? (Easy?)

in my game, the character can only walk forward in a strait line and cant walk backwards.
I want to check when the player has walked an amount of units.
then I want to play an animation.

I tried something like:

if (gameobject.transform.position.y = XX)
{
animation.play;
}

then it tells me:
error CS0236: A field initializer cannot reference the nonstatic field, method, or property `UnityEngine.Component.gameObject’

what can I do instead???

Not sure if it was intentional, but shouldn’t you have put == instead an = in an if statement. Also, you should measure the distance traveled, not the postion of your object. Something roughly like this might work:

var DistanceTraveled : float = SPEED * TIME;
var MinAnimDistance = XX;
if (DistanceTraveled >= MinAnimDistance){ animation.play;}

Not entirely sure though.