Reputation: 21
I've been trying to make my camera stop moving at a certain point for some time now and I've looked at various other answers but decided to make my own code. The code makes sense to me but for some reason does not work as when it is attached to the camera in unity the camera is constantly blue (Which is my background colour). The camera seems it is in the correct position to be able to see at least something so I'm very stuck here.
public float minPos = 0.3234783f;
public float maxPos = 40f;
Vector2 tempPos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
tempPos = transform.position;
if (transform.position.x == minPos) {
tempPos.x = minPos;
}
transform.position = tempPos;
Here is my code I'm hoping someone can figure this out, thanks!
Note: The Game Is 2D
Upvotes: 0
Views: 1060
Reputation: 4888
It could be that you moved the camera right at the position of object you were following, hence you can't see it. All you have to do to fix this is to offset the camera on the Z axis back to where it was before.
tempPos = transform.position;
tempPos.z = -10f;
Upvotes: 1