I’m trying to make a script for the camera that has the camera follow the player in Unity 2D. Without the script attached to the camera, the player renders fine, but once I attach the script, the player and all other objects vanish. Even after I detach the script, the player is still invisible. As far as I can tell, this has to do with the transform of the camera, but I have no idea how to fix it.
using UnityEngine;
using System.Collections;
public class CameraUpdater : MonoBehaviour {
private Transform player;
void Start () {
player = GameObject.Find ("Player").transform;
}
void Update () {
Vector2 playerpos = player.position;
playerpos.x = transform.position.x;
playerpos.y = transform.position.z;
transform.position = playerpos;
}
}