You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
using System.Collections.Generic ;
using Fusion ;
using UnityEngine ;
public class Networked_Characters : NetworkBehaviour
{
// Make a universal list of the available prefabs. Set the values in Editor.
public List < GameObject > NetworkedCharacterPrefabs ; // Would have your male and female versions here.
// Call this by the local client once the Male or female character is selected.
public void RequestSpawnObject ( PlayerRef playerRequesting , int prefabIndex )
{
RPC_ServerSpawnCharacter ( playerRequesting , prefabIndex ) ;
}
// this will be called on the Server only by the above function.
[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
private void RPC_ServerSpawnCharacter ( PlayerRef playerRequesting , int prefabIndex )
{
NetworkObject netObj = Runner . Spawn ( NetworkedCharacterPrefabs [ prefabIndex ] , Vector3 . zero , Quaternion . identity , playerRequesting ) ; // The last parameter sets the InputAuthority over the character Object.
RPC_ClientSetCharacter ( playerRequesting , netObj . Id ) ;
}
// Then I use something like this to let the client know which character spawned is theirs by giving the client the NetworkId of the object.
// Using a targeted RPC will make it so the proper client is given the specific character NetworkID.
[Rpc(RpcSources.StateAuthority, RpcTargets.All)]
private void RPC_ClientSetCharacter ( [ RpcTarget ] PlayerRef player , NetworkId objectNetId )
{
// GameObject character = Runner.FindObject(objNetId).gameObject;
// Add any code here necessary. This is on the client and the character gameobject they wanted spawned is "character" above.
}
}