Locking the Camera to Instantiated Player

Hi guys, having an issue getting this to work.
I have the player select a ship, which assigns them an Int, using the Int, I initiate into the ‘Game’ screen their ship through the Gamemanager, this screen doesn’t have a Camera, as I want it to be linked to the player, and only focus on them, so the PlayerPrefab has the Camera script, however, it doesn’t work, what am I doing wrong, I’m stumped…

Inst’d Code

using UnityEngine;
using System.Collections;

public class PlayerInstantiateScript : MonoBehaviour {

	//Instatiate based on which bool.
	public GameObject PlayerRocket1;
	public GameObject PlayerRocket2;
	public GameObject PlayerRocket3;
	
	// Use this for initialization
	void Start () {

		if (ChangeShipName.ShipChoice==1)
		{
		
			Instantiate(PlayerRocket1, new Vector3(531, 59, 0), Quaternion.Euler(270, 0, 0));
		}
		else 
			if (ChangeShipName.ShipChoice==2)
		{
			
				Instantiate(PlayerRocket2, new Vector3(531, 59, 0), Quaternion.Euler(270, 0, 0));
		}
		else
			if (ChangeShipName.ShipChoice==3)
		{
			
				Instantiate(PlayerRocket3, new Vector3(531, 59, 0), Quaternion.Euler(270, 0, 0));
		}

	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

Camera Code

using UnityEngine;
using System.Collections;

public class CameraStalkPlayer : MonoBehaviour {


	public Transform player;
	public Vector3 offset;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		transform.position = new Vector3 (player.position.x + offset.x, player.position.y + offset.y, offset.z); // Camera follows the player with specified offset position
	}
}

It’s not exactly clear what you’re trying to do from your questions.

However, if you want to have a camera follow a transform that is created at runtime you can do it like this.

Create a camera with CameraStalkPlayer on it in the scene where you will instantiate the player rocket.

Add a public CameraStalkPlayer in your PlayerInstantiateScript and set it to the newly created camera in the editor.

Now you can do

    void Start () {
     
             if (ChangeShipName.ShipChoice==1)
             {
                 GameObject player = Instantiate(PlayerRocket1, new Vector3(531, 59, 0), Quaternion.Euler(270, 0, 0)) as GameObject;
                 cameraStalk.player = player.transform;
             }

@TheAMD
You need to make your CameraStalkPlayer script’s “player” variables public static in order to access it from another script (unless u design it as a singleton - which you can research on it further)

But for now do this:

public class CameraStalkPlayer : MonoBehaviour {
 
 //......
     public static Transform player;
 //.....
 }

and in the other script like this

public class PlayerInstantiateScript : MonoBehaviour {

// .....
         if (ChangeShipName.ShipChoice==1)
         {
         
             GameObject playerInstance = Instantiate(PlayerRocket1, new Vector3(531, 59, 0), Quaternion.Euler(270, 0, 0));
             CameraStalkPlayer.player = playerInstance.transform;
         }
// .....
 }