Hello. I want my camera to follow the player’s x coordinate, but only in one direction (it is a 2D game, so the camera will follow the player when they are traveling to the right, but the camera will not move to the left). Here is my script, how can I modify it to do what I want? Thanks
function Update (){
var Player = GameObject.Find("Player");
transform.position.x=Player.transform.position.x;
}
first you want to move the var player to start code otherwise you are constantly looking for game objects every frame.
second you need var camera and do a game object.find camera.
finally in your update do the camera.transform.position.x = player.transform.position.x if it’s first person 2D (not sure how that will work unless you are looking straight down on it… otherwise you are probably going to want to update the Z not the X…