Unity
2D Camera Follow Player
Introduction
This is a very very simple camera script that will follow the object named "Player"
Features
Camera will follow the object named "Player"
The Code
License Terms
Attribution 3.0 Unported - You must attribute the work in the manner specified by the author or licensor. Commerical use allowed.
Frequently Asked Questions
Q: Why wont the camera follow my player?
A: Make sure the OBJECT is named Player, not the tag. Also make sure you attached the script to the camera and not the player
Instructions
Step 1:
Attach this script to any camera.
Step 2:
Name the object you want the camera to follow "Player" minus the quotes
Author Notes
This script is meant for 2D only. I will not give support if your trying to use it for 3D.
Version History
1.1 – Added ability to zoom in and out via mouse wheel.
Comments (4)
Leave a Reply
You must be logged in to post a comment.
Bob423
Another way to do this is to just drag the main camera object onto the player object in the hierarchy. Any object that is a "child" of another object will move when it's parent does, but can still move independently.
drago2308
Nice little script for a 2d game, i'm contemplating if I should upload my advanced camera script here. (its big and comes in multiple parts (for triggers to control extra movement and stuff). but for 4 lines your script gets the job done for a 2d game.
Polraudio
[quote]Another way to do this is to just drag the main camera object onto the player object in the hierarchy. Any object that is a "child" of another object will move when it's parent does, but can still move independently.[/quote] Its a way but the problem with that is when you want to rotate your object for whatever reason the camera will also rotate and it gets very annoying. Especially when you want your character to wobble for moving.
Polraudio
Updated the script. Added the ability to zoom in and out with the mouse wheel.