Hello,
I have a problem with a script I am using that would make the camera follow the player, (same as unity 2DCameraFollow), but it would ignore the movements in the Y axis, and just follow the player in the X axis (basically, when the players moves from left to right, the camera follows, but when it jumps, it doesn’t).
I’ve been using unity script till now, the Camera2DFollow, which works perfectly, but now I’ve tried to make a similar script, which would ignore the Y axis movements, and what I see is just the “Skybox”, basically I see the UI and nothing else.
The game is 2D by the way, and obviously the script is attached to the Main Camera and has as target the player.
Here the code that gives problems :
using System;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public GameObject Target; //Public variable to store a reference to the player game object
public Vector2 offset; //Private variable to store the offset
void Update()
{
// Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance.
Vector2 newPos = new Vector2(Target.transform.position.x, 0);
transform.position = newPos + offset;
}
}
Any help is greatly appreciated, I am having a lot of trouble with this script.
Thank you all in advance.