Skip to main content
added 10 characters in body
Source Link

In the player script, you could find the camera and make it follow the player with:

GameObject cam = GameObject.FindWithTag("Camera"); //assuming Camera has tag Camera cam.transform.setParent(this.gameObject); 

This makes the player the parent of the camera. This essentially does what the drag and drop does, but through code, so it works with prefabs.

In the player script, you could find the camera and make it follow the player with:

GameObject cam = GameObject.FindWithTag("Camera"); //assuming Camera has tag Camera cam.setParent(this.gameObject); 

This makes the player the parent of the camera. This essentially does what the drag and drop does, but through code, so it works with prefabs.

In the player script, you could find the camera and make it follow the player with:

GameObject cam = GameObject.FindWithTag("Camera"); //assuming Camera has tag Camera cam.transform.setParent(this.gameObject); 

This makes the player the parent of the camera. This essentially does what the drag and drop does, but through code, so it works with prefabs.

Source Link

In the player script, you could find the camera and make it follow the player with:

GameObject cam = GameObject.FindWithTag("Camera"); //assuming Camera has tag Camera cam.setParent(this.gameObject); 

This makes the player the parent of the camera. This essentially does what the drag and drop does, but through code, so it works with prefabs.