C# Script On Camera Hides Player?
I've obviously not set something up properly in my space, but I don't know what.
I've just attached this C# script to my camera:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
public Transform player;
public Vector3 offset;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = new Vector3(player.position.x + offset.x, player.position.y + offset.y);
}
}
Yet for some reason this now hides my 2D Player object. If I disable the script on the camera, the player ship shows up fine.
Below are screenshots of the set up of each object.
Any help would be greatly appreciated!
Answer by xxmariofer · Oct 14, 2021 at 07:58 AM
change to
transform.position = new Vector3(player.position.x + offset.x, player.position.y + offset.y, -10);
Your answer
Follow this Question
Related Questions
If player hits certain X value in opposition to Camera, shift camera question. 0 Answers
cinemachine 2d look-ahead problem in respawn 2 Answers
Trying to make a 2D Panning Camera 0 Answers
Using two cameras to blend regular 2D orthographic with 3D isometric orthographic elements 0 Answers
I want to make my camera follow the player ONLY when the player is on solid ground [2D] 0 Answers