Search Unity

Third Party Player Instantiate camera Put it in

Discussion in 'Multiplayer' started by kimkb3174, Aug 30, 2023.

  1. kimkb3174

    kimkb3174

    Joined:
    Feb 6, 2023
    Posts:
    1
    I instantiate the player in PUN2 and then find the player in the camera update, and when I find the player with FindObject, I find the first thing I meet and other player objects are included, so how can I solve it

    public class CameraControl : MonoBehaviourPunCallbacks
    {

    [SerializeField]
    Vector3 _delta;

    Vector3 offset;

    [SerializeField]
    Transform _player;


    void Update()
    {
    _player = FindObjectOfType<PlayerControl>().transform;
    transform.position = _player.position + _delta;
    }
    }
    ------------------------------------------------------------------------------------------------------------------------------------------------
    void CreateController()
    {
    Transform spawnPoint = SpawnManager.Instance.GetSpawnPoint();

    GameObject playerToSpawn = playerPrefabs[0];
    var controller = PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", playerToSpawn.name), spawnPoint.position, Quaternion.identity, 0, new object[] { PV.ViewID });
    controller.name = playerToSpawn.name;
    }

    I want to find myself and assign a camera