- Home /
Different Camera changes work against each other?
So in my Camera script, I have two separate, for lack of a better word, functions that allows you to zoom as well as move your camera around. (Both of them are in the update function, so just remember that it isn't actually a function.) You can drag the camera around by holding Middle Mouse button and dragging; and you can zoom in an out using your scroll wheel. However, this clashes together, because of my script. My script is as follows (pay attention to lines 18-24 the most. I believe it has something to do with the second if statement):
void Update () {
if (Input.GetMouseButtonDown(2)) {
dragOrigin = Input.mousePosition;
}
if(!Input.GetMouseButton (2)) {
return;
}
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
Vector3 move = new Vector3(pos.x * dragSpeed, 0, pos.y * dragSpeed);
transform.Translate(move, Space.World);
if(Input.GetAxis ("Mouse ScrollWheel") < 0) {
if(Camera.main.fieldOfView <= 50) {
Camera.main.fieldOfView += 2f;
}
if(Camera.main.orthographicSize <= 20) {
Camera.main.orthographicSize += 0.5f;
}
}
if(Input.GetAxis("Mouse ScrollWheel") > 0) {
if(Camera.main.fieldOfView > 20) {
Camera.main.fieldOfView -= 2f;
}
if(Camera.main.orthographicSize >= 1) {
Camera.main.orthographicSize -= 0.5f;
}
}
}
NV$$anonymous$$. Solved it. I just had to put the camera movement part inside a separate function.
If this problem is solved you should either close the question or answer it yourself and accept the answer. Otherwise people like me will come here, read the question, then read the comments and find out it's already been answered. We wouldn't do that if it was closed or already answered! :)
Answer by TrivialRoo · Dec 27, 2013 at 12:37 PM
I solved my problem, sorry, but this is the only way I know how to close a question.
Your answer
Follow this Question
Related Questions
Camera movement and zoom bounds 0 Answers
How to make a camera zoom on a particular part of image plane? 1 Answer
Camera and Mouse Movement 0 Answers
How do you differentiate between pinch to zoom with two fingers and a two finger drag? 2 Answers
Move a cube with mouse relative to the camera rotation 0 Answers