- Home /
Question by
Intruder_Excluder · May 25, 2017 at 02:53 PM ·
camera2d game2d-platformeraxis
How to make the camera move up and down the horizontal axis only when the 2D character get's above and below the top half of the screen.
Here is some code on the camera script that someone gave me that was successful in making the camera move up horizontally when the 2D character moves up to the top half of the screen---
if (target.transform.position.y > transform.position.y + 3f) {
targetPosition = new Vector3 (target.transform.position.x, target.transform.position.y, transform.position.z);
}
The only problem is that I can't figure out how to get the camera to move down the horizontal axis when the 2D character goes below the top half of the screen.
Does anybody know how to execute that through code?
Comment
Just add another one but inverted?
if (target.transform.position.y < transform.position.y + 3f) {
targetPosition = new Vector3 (target.transform.position.x, target.transform.position.y, transform.position.z);
}