Here’s my code:
GameObject.transform.position = new Vector3(GameObject.FindGameObjectWithTag("Player").transform.position.x, 0);
This code is linked to the main camera
Here’s my code:
GameObject.transform.position = new Vector3(GameObject.FindGameObjectWithTag("Player").transform.position.x, 0);
This code is linked to the main camera
Hi @
First lesson to learn with Unity - google everything first which you don’t know. Most basic stuff is explained and has several tutorials created by Unity and YouTube creators etc…
If you just google:
unity move camera
You’ll find several examples.
public Transform playerObject; // Drag your player inside the inspector
// Your camera move script should be on your camera so you wont need a variable for that.
private void Update()
{
transform.position = playerObject.position;
// Since the script is on the camera you're accessing its GameObject.transform.position.
// You only need to set it to that of the players.
}