2D Collision detection is off when getting nearer to edge of screen

I’ve been working on a project using the NGUI system for the 2D. Since there is no built-in collision detection for the images, I had to make one myself, and it is accurate in the center of the screen, but nearer the end, it starts getting off. The camera never moves and the wall itself doesn’t move, only the character. Can someone help me? Here is my collision code-

public int[] checkForCollision(){
		decimal cX = Character.x;
		decimal cY = Character.y;
		decimal cW = (decimal) Character.person.transform.lossyScale.x;
		decimal cH = (decimal) Character.person.transform.lossyScale.y;
	
		decimal cU = cY;
		decimal cD = decimal.Subtract(cY, cH);
		
		decimal wU = y;// + (height / 2);
		decimal wD = decimal.Subtract(y, height);
		int[] returnList = new int[3];
		
		if (cD < wU  cU > wU){
			Debug.Log("Bottom of Character collide with top of wall!");	
			returnList[0] = 1;
			returnList[1] = -1;
		} else if (cU > wD  cD < wD){
			Debug.Log("Top of Character collide with bottom of wall!");
			returnList[0] = 1;
			returnList[1] = 1;
		}else {
			returnList[0] = 0;	
		}
		
		return returnList;
	}

Can someone help me?

Can someone please help me? I can’t figure out how to fix this.

Your code is too simple to have something wrong with it. It’s either a problem with ngui, or it has to do with camera perspective. Since probably a few or none of us have ngui, it’s really not the right place to ask. It would be better to ask the author on his thread. The one thing I could suggest is to make sure your camera is in orthographic mode if this is a 2d application.

My camera has been on orthographic, but thanks anyways. :wink: