- Home /
Camera Script Making Player Vanish
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;
}
}
Answer by RLin · Aug 06, 2015 at 05:10 PM
Remove everythin in update and just leave transform.position = player.position
Thanks! It works now, I had to do that and subtract 10 from the z transform (I unintentionally put this in as a response!)
That helped me fix it, thanks! It had the same issue, but it was super zoomed in, so I just subtracted 10 from the z transform.
This is my first time using unity answers. How do I mark it as answered?
Your answer
Follow this Question
Related Questions
2D Camera Smooth follow, FixedUpdate and LateUpdate odd difference, help needed. 1 Answer
Help with a 2d camera Controller 1 Answer
How to Manually Move the Camera Horizontally or Vertically? (2D, Parallax), 0 Answers
2d camera panning 1 Answer
Why is Input.mousePosition returning wired values using Cinemachine 2D with dynamic following? 0 Answers