Prevent changing position

I’m making a platformer game, so I want the player to has the Z axis always to zero.
I made this part of script, but it doesn’t work. How should I fix it?

if(transform.position.z > 0)
{
	transform.position.z = 0;
}

1 Answer

1

Try this:

function Update() {
     transform.position = Vector3(transform.position.x, transform.position.y, 0);
}

Thanks! It was so simple!