- Home /
Cam Prefab not showing anything with Photon
I have photon spawn 2 prefabs, a player and a unparented cam. The cam finds the tag and targets the player. Works nicely except in game the camera just shows the default blue background. In the scene view i click the camera and even its preview is the blue. But if i drag the camera prefab into the scene in the inspector and then click on it it shows what its supposed to. There are no errors, nothing i can think about either :/.
Here is my code involved:
1. CameraScript. (on camera prefab)
using UnityEngine;
using System.Collections;
public class CameraScript : Photon.MonoBehaviour {
public float dampTime = 0.10f;
private Vector3 velocity = Vector3.zero;
public Transform target;
void Start () {
}
void FixedUpdate () {
target = GameObject.FindGameObjectWithTag ("camerafollowme").transform;
if (target) {
Vector3 point = GetComponent<Camera> ().WorldToViewportPoint (target.position);
Vector3 delta = target.position - GetComponent<Camera> ().ViewportToWorldPoint (new Vector3 (0.5f, 0.3f, point.z)); //(new Vector3(0.5, 0.5, point.z));
Vector3 destination = transform.position + delta;
transform.position = Vector3.SmoothDamp (transform.position, destination, ref velocity, dampTime);
}
}
}
Player_NetworkSetup (On player prefab)
using UnityEngine; using System.Collections;
public class Player_NetworkSetup : Photon.MonoBehaviour {
GameObject myCamera; // Use this for initialization void Start () { myCamera = GameObject.FindGameObjectWithTag ("playercamera"); if (photonView.isMine) { myCamera.SetActive (true); GetComponent<PlayerController1> ().enabled = true; } else { myCamera.SetActive (false); } } void Update () { } }
Network Manager (in scene)
using UnityEngine; using System.Collections;
public class NetworkManager : Photon.MonoBehaviour {
public string roomName = "DaveisFat"; public string playerPrefabName = "player"; public string CameraPrefabName = "playercamera"; public Transform spawnPoint; void Start () { PhotonNetwork.ConnectUsingSettings ("0.1"); } void OnGUI(){ GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ()); } //this is setting for your lobby room like can others see it and how many ppl can join void OnJoinedLobby(){ RoomOptions roomOptions = new RoomOptions() { isVisible = false, maxPlayers = 4}; PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);} // PhotonNetwork.JoinRandomRoom (); // } void OnPhotonRandomJoinFailed(){ // PhotonNetwork.CreateRoom (roomName); } //When someone joins have the prefab spawn at the SpawnPoint (game object)'s position void OnJoinedRoom() { PhotonNetwork.Instantiate (playerPrefabName, spawnPoint.position, spawnPoint.rotation, 0); PhotonNetwork.Instantiate (CameraPrefabName, spawnPoint.position, spawnPoint.rotation, 0); } }
Your answer
Follow this Question
Related Questions
Help with PUN PhotonNetworkView stuff. 1 Answer
Unity camera troubles 1 Answer
Player Won't Instantiate with Photon Unity Network [PUN] 0 Answers
Photon Unity Networking - Player Camera Instantiate 0 Answers
Camera frustums + custom field of view 2 Answers