position

HI
I wrote this code:

public void Update()
	{
		if(transform.position.y = 7f)
		{
			transform.position.y = 7f;
		}
	}

It should stop the player movement when it get to y = 7
but the unity wrote me:
Assets/Position.cs(8,30): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable
how can fix it?
I try to create variable that stores the value but it didnt work
thx for the help

Try this:

public void Update() 
{ 
	float stopAt = 7f;
	if(transform.position.y == stopAt) 
    { 
		Vector3 current = transform.position;
		transform.position = new Vector3( current.x, stopAt, current.z ); 
	} 
}

Now I don’t know what’s moving, but the chances of it ever being exactly 7 are low.
Try using the <= or the >= instead if this code doesn’t seem to work.

Hope this helps.

thx for the help
I Thoth that will work like xna