This script allows for basic camera manipulation including panning, zooming, and rotating around a specified target in a Unity scene.
-
Clone the Repository:
git clone https://github.com/hsuehyt/CameraController.git
-
Create GameObjects in the Scene:
- Open your Unity project.
- In the Hierarchy, right-click and create two empty GameObjects.
- Name them exactly as follows:
userPoint
cameraAim
-
Organize Hierarchy:
- Drag the
Main Camera
underuserPoint
.
- Drag the
-
Assign the Script:
- Attach the
CameraController.cs
script to any GameObject (e.g.,userPoint
). - In the Inspector, assign the
userPoint
andcameraAim
GameObjects to their respective fields in the script.
- Attach the
-
Ensure Correct Naming:
- Make sure the names are case-sensitive and exactly match
userPoint
andcameraAim
.
- Make sure the names are case-sensitive and exactly match
- Pan: Middle mouse button + mouse movement
- Zoom: Right mouse button + mouse movement (up/down)
- Rotate: Left mouse button + mouse movement (around
cameraAim
) - Reset to Default Position: Press
F