BillForest
Member
So I have a character selection script that works, and I have a script that can instantiate the chosen character into a Pun Scene but my problem is when I try and connect it to Opsive UCC. I think I need to combined my "Instantiate Script" to your "Single Character Spawn Manager Script". I have tried doing that which just ends in a bunch of errors and problem,s so I was hoping you could tell me how to combined the two scripts in order to load my Opsive prefabs.
Please help me, I think its just a matter of connecting your m_Character, right?
My Script-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
using Photon.Pun;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Collections.Specialized;
public class MultiplayerCharacterSpawnManager : MonoBehaviour
{
public GameObject[] PlayerPrefabs;
public Transform[] InstantiatePositions;
void Start()
{
if (PhotonNetwork.IsConnectedAndReady)
{
object playerSelectionNumber;
if (PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue(RIGame.PLAYER_SELECTION_NUMBER, out playerSelectionNumber))
{
UnityEngine.Debug.Log((int)playerSelectionNumber);
int actorNumber = PhotonNetwork.LocalPlayer.ActorNumber;
Vector3 instantiatePosition = InstantiatePositions[actorNumber - 1].position;
PhotonNetwork.Instantiate(PlayerPrefabs[(int)playerSelectionNumber].name, instantiatePosition, Quaternion.identity);
}
}
}
}
Your Script-
/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game
{
using UnityEngine;
using Photon.Realtime;
/// <summary>
/// Manages the character instantiation within a PUN room.
/// </summary>
public class SingleCharacterSpawnManager : SpawnManagerBase
{
[Tooltip("A reference to the character that PUN should spawn. This character must be setup using the PUN Multiplayer Manager.")]
[SerializeField] protected GameObject m_Character;
public GameObject Character { get { return m_Character; } set { m_Character = value; } }
/// <summary>
/// Abstract method that allows for a character to be spawned based on the game logic.
/// </summary>
/// <param name="newPlayer">The player that entered the room.</param>
/// <returns>The character prefab that should spawn.</returns>
protected override GameObject GetCharacterPrefab(Player newPlayer)
{
// Return the same character for all instances.
return m_Character;
}
}
}
Thanks
Please help me, I think its just a matter of connecting your m_Character, right?
My Script-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
using Photon.Pun;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Collections.Specialized;
public class MultiplayerCharacterSpawnManager : MonoBehaviour
{
public GameObject[] PlayerPrefabs;
public Transform[] InstantiatePositions;
void Start()
{
if (PhotonNetwork.IsConnectedAndReady)
{
object playerSelectionNumber;
if (PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue(RIGame.PLAYER_SELECTION_NUMBER, out playerSelectionNumber))
{
UnityEngine.Debug.Log((int)playerSelectionNumber);
int actorNumber = PhotonNetwork.LocalPlayer.ActorNumber;
Vector3 instantiatePosition = InstantiatePositions[actorNumber - 1].position;
PhotonNetwork.Instantiate(PlayerPrefabs[(int)playerSelectionNumber].name, instantiatePosition, Quaternion.identity);
}
}
}
}
Your Script-
/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game
{
using UnityEngine;
using Photon.Realtime;
/// <summary>
/// Manages the character instantiation within a PUN room.
/// </summary>
public class SingleCharacterSpawnManager : SpawnManagerBase
{
[Tooltip("A reference to the character that PUN should spawn. This character must be setup using the PUN Multiplayer Manager.")]
[SerializeField] protected GameObject m_Character;
public GameObject Character { get { return m_Character; } set { m_Character = value; } }
/// <summary>
/// Abstract method that allows for a character to be spawned based on the game logic.
/// </summary>
/// <param name="newPlayer">The player that entered the room.</param>
/// <returns>The character prefab that should spawn.</returns>
protected override GameObject GetCharacterPrefab(Player newPlayer)
{
// Return the same character for all instances.
return m_Character;
}
}
}
Thanks