code doesn't do what i want it to

a while back i made an RTS camera system albeit a simple one, its worked perfectly up until the latest unity update version 5.1.1f1, all but one segment of code works but its important to its functionality here is the code what is wrong with this

using UnityEngine;
using System.Collections;

public class cameramovement : MonoBehaviour
{
	
	public int edgeboundry = 10;
	public int minheight;
	public int maxheight;
	bool minheightreached;
	bool maxheightreached;
		
	void Awake ()
	{
		minheightreached = false;
		maxheightreached = false;
	}
	
	void Update ()
	{
		
		 
		
				
		
		if (transform.position.y >= minheight) {
			minheightreached = true;
		}
		if (transform.position.y <= maxheight) {
			maxheightreached = true;
		}

		
		if (Input.GetKey ("left ctrl") && (Input.mousePosition.y < Screen.height / edgeboundry) || (Input.GetAxis ("Vertical") < 0 * Time.deltaTime)) {            
			
			transform.position += new Vector3 (0, 0, -0.2f);
			
		}
		
		if (Input.GetKey ("left ctrl") && (Input.mousePosition.y > Screen.height - Screen.height / edgeboundry) || (Input.GetAxis ("Vertical") > 0 * Time.deltaTime)) {             
			
			transform.position += new Vector3 (0, 0, 0.2f);
		}
				
		if (Input.GetKey ("left ctrl") && (Input.mousePosition.x < Screen.width / edgeboundry) || (Input.GetAxis ("Horizontal") < 0 * Time.deltaTime)) {            
			transform.position += new Vector3 (-0.2f, 0, 0);
			
		}
		if (Input.GetKey ("left ctrl") && (Input.mousePosition.x > Screen.width - Screen.width / edgeboundry) || (Input.GetAxis ("Horizontal") > 0 * Time.deltaTime)) {           
			
			transform.position += new Vector3 (0.2f, 0, 0);
				
		}
		if (Input.GetAxis ("Ymovement") < 0 && (minheightreached = false)) {   //this is the offending segment 
				
			transform.position += new Vector3 (0, 0.2f, 0);
				
				
		}
		if (Input.GetAxis ("Ymovement") > 0 && (maxheightreached = false)) {  //this is the offending segment    
					
			transform.position += new Vector3 (0, -0.2f, 0);
		}
					
					
	}
}

the segment stated controls up and down movement on the Y axis as stated all the rest do their intended job but the marked bit don’t

i would also like to explane that the code itself is on a gameobject with the camera parented to it and its the gameobject that is raising and lowering, in the inspector the minheight variable is set to 4 and the maxheight variable is set to 40 p.s the ymovement input is also set correctly in the input section of the edit menu

thanks in advance to everyone that helps

You’re assigning, not comparing…

(minheightreached = false) should be (minheightreached == false)

(maxheightreached = false) should be (maxheightreached == false)

Speaking only in terms of the Y-Axis movement, what exactly is the behavior you are trying to achieve?

There are a few logical issues with this code and with the way it is currently structured the object’s position will always be updated in the negative direction along the Y-Axis. On lines 54 & 60, you are accidentally using the assignment operator instead of the equality operator. Also, once your min/maxheightreached variables are set to true inside of your Update method, they are never set back to false which will always result in your last two ‘if’ statements returning false. Try out the following changes and see if they help you.

At the top of ‘Update’ method, replace the first two ‘if’ statements with:

minheightreached = transform.position.y <= minheight;
maxheightreached = transform.position.y >= maxheight;

Replace your last two ‘if’ statements with:

if(Input.GetAxis("Ymovement") > 0.0f && (maxheightreached == false))
{ 
    transform.position += new Vector3(0, 0.2f, 0);
}
if(Input.GetAxis("Ymovement") < 0.0f && (minheightreached == false))
{
    transform.position += new Vector3(0, -0.2f, 0);
}

Again, I’m not 100% sure what your intended behavior is, but this should help you get back on track.