Question by
Raviraja190 · Oct 24, 2016 at 01:51 PM ·
movementplayerbounds
Player is not moving if i apply the Playerbounds
using UnityEngine; using System.Collections;
public class PlayerBounds : MonoBehaviour { private float minX,maxX;
void SetMinAndMaxX(){
Vector3 bounds = Camera.main.ScreenToWorldPoint (new Vector3 (Screen.width, Screen.height, 0));
maxX = bounds.x;
minX = -bounds.x ;
}
// Use this for initialization
void Start () {
SetMinAndMaxX();
}
// Update is called once per frame
void Update () {
if (transform.position.x < minX) {
Vector3 temp = transform.position;
temp.x = minX;
transform.position = temp;
}
if(transform.position.x > maxX){
Vector3 temp = transform.position;
temp.x = maxX;
transform.position = temp;
}
}
}
Comment
Your bounds don't make sense.
Camera.main.ScreenToWorldPoint() will take a screen point and fire it into the world by given distance (your Vector3's Z value). Your function is essentially taking a screen point and firing it 0 units into the world from your camera, which will give you the exact location of your camera.
Well, there are a few ways to tackle this. Since you're only adjusting the X-dimension of your camera, I'm assu$$anonymous$$g this is a 2D game side-scrolling game?
Yes The problem had solved. i changed the camera from Perspective to Orthographic. It Worked right now