- Home /
minimap zooming c#
hello i have made a mini map and i want to be able to when i hover over the minimap it start scrolling ive made the camera scroll the problem is it scrolls my main camera as well how would i go about doing this here is the code for the scrolling so far in c#:
using UnityEngine;
using System.Collections;
public class miniMapCamera : MonoBehaviour {
public float minZoom = 2f;
public float maxZoom = 50f;
void Update() {
camera.fieldOfView = 21f;
if(Input.GetAxis("Mouse ScrollWheel") > 0) {
camera.fieldOfView--;
if(camera.fieldOfView < minZoom){
camera.fieldOfView = minZoom;
}
else if(Input.GetAxis("Mouse ScrollWheel") < 0) {
camera.fieldOfView++;
if(camera.fieldOfView > maxZoom) {
camera.fieldOfView = maxZoom;
}
}
}
}
}
any help will be appreciated
Answer by yeoldesnake 1 · Sep 26, 2011 at 02:00 PM
You seem to be editing the main camera's field of view , if this script is attached to the object containing the main camera it will modify it's FoV as well. You can try defining the minimap camera as either a gameobject from which you will get the camera component , or directly as a Behaviour , and modify the field of view of that camera. Or you can simply remove this script from your main camera object , if the script is already attached to the minimap camera object. Another thing i saw is that you are constantly setting the camera field of view every frame in Update()
camera.fieldOfView = 21f;
I wonder how it is functional in the first place.
Another piece of advice regarding zooming in and out. It is best to use
if(Input.GetAxis("Mouse ScrollWheel") > 0&&camera.fieldOfView > maxZoom){
camera.fieldOfView++;
if(camera.fieldOfView > maxZoom) {
camera.fieldOfView = maxZoom;
}
}
To avoid the camera zooming in then instantly out when the FoV is equal to the minimum or maximum values , the extra check after incrementing the field of view is for precaution safety measures.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130618im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Camera only panning on 1 axis 1 Answer
Camera following dice with FREE UNITY DICE PACK. help 1 Answer
How to use vuforia AR Camera for Zoom 1 Answer
Drawing a minimap - need an advice 1 Answer