Answer the question
In order to leave comments, you need to log in
How to pass the dynamic prefab of the main player to another script (Photon Pun)?
Hello.
There is an object (Game Manager) with a script on it (GameManager.cs).
GameManager.cs spawns a player with a prefab:
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviourPunCallbacks
{
public GameObject PlayerPrefab;
void Start()
{
Vector3 pos = new Vector3(Random.Range(-3f, 3f), Random.Range(-3f, 3f));
PhotonNetwork.Instantiate(PlayerPrefab.name, pos, Quaternion.identity);
}
...
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public GameObject PlayerPrefab;
[SerializeField]
private float speed = 2.0F;
public Vector3 offset;
[SerializeField]
public Transform target;
private void Awake()
{
//if (!target) target = FindObjectOfType<Тут надо найти копию префаба/объекта игрока, который заспавнился, которым будем управлять>().transform;
}
private void Update()
{
Vector3 position = target.position + offset;
position.z = -10.0F;
transform.position = Vector3.Lerp(transform.position, position, speed * Time.deltaTime);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question