Hello so in my game I want to be able to zoom in and out using the mouse wheel, as well as use the camera scripts and movement which come with ac
I wrote a script however I feel like it inteferes the current camera scripts which come with ac,
that or I may be a little rusty on the coding,
would appreciate if anyone could have a look at my code give me some pointers how to properly implement this feature . heres what I wrote :
Using UnityEngine;
public class CameraZoom : MonoBehaviour
{
public float zoomSpeed = 1.0f;
void Update()
{
float scrollWheelInput = Input.GetAxis("Mouse ScrollWheel");
Camera.main.orthographicSize -= scrollWheelInput * zoomSpeed;
}
}
Thanks guys
I am using Unity version 2022.1.7f1
I am using Adventure creator Version V1.76.3
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
The issue looks to be to do with its affecting of "Camera.main", which will refer to AC's MainCamera.
AC's MainCamera works by attaching itself to the active "GameCamera", which involves copying over its values each frame - this includes the orthographic size. What's happening is that this attachment is overriding your script's setting of this value.
What you'd need to do is instead have the script affect the GameCamera the MainCamera is attached to - since changes made to the GameCamera will then also affect the MainCamera each frame.
You can do this by replacing
Camera.main
to have it affect the Camera it's attached to - just be sure to attach the script to the GameCamera you want it to affect:Thanks Chris ! A lifesaver as usual