I have two issues with this script. 1. to get the correct margin on the right, I had to take out the /2 from the else if statement:
else if (playerPosScreen.x > Screen.width / 2 – screenX)
{
transform.position = Camera.main.ScreenToWorldPoint(new Vector3(
Screen.width / 2 – screenX,
playerPosScreen.y,
playerPosScreen.z));
}
Secondly, If you got to the side margin, keep pressing into it, and go down/up, you can get passed the bottom and top margin, I can’t figure out how to fix this, I’ll look at the code more, if I figure it out, I’ll post the code here.
November 20th, 2014 on 1:18 am
Very good post! 🙂
July 4th, 2015 on 5:17 pm
I have two issues with this script. 1. to get the correct margin on the right, I had to take out the /2 from the else if statement:
else if (playerPosScreen.x > Screen.width / 2 – screenX)
{
transform.position = Camera.main.ScreenToWorldPoint(new Vector3(
Screen.width / 2 – screenX,
playerPosScreen.y,
playerPosScreen.z));
}
Secondly, If you got to the side margin, keep pressing into it, and go down/up, you can get passed the bottom and top margin, I can’t figure out how to fix this, I’ll look at the code more, if I figure it out, I’ll post the code here.
November 24th, 2015 on 12:39 am
I actually improved more this code to work with different screen aspect ratios (sometimes we use a black line on the left & right margins).
Will try to post an updated version of this code.