Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Player Colors #75

Merged
merged 10 commits into from
Dec 7, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ Transform:
m_CorrespondingSourceObject: {fileID: 8338988566280778637, guid: 64dce48905ffd9b4293e595fa6941544, type: 3}
m_PrefabInstance: {fileID: 3616664937583670245}
m_PrefabAsset: {fileID: 0}
--- !u!1 &4877212143847805304 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8187455079231382173, guid: 64dce48905ffd9b4293e595fa6941544, type: 3}
m_PrefabInstance: {fileID: 3616664937583670245}
m_PrefabAsset: {fileID: 0}
--- !u!114 &3615669438616969171
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4877212143847805304}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0bcad93ad8ac5d4449dd8f76d5db9990, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!95 &5969265393934875124 stripped
Animator:
m_CorrespondingSourceObject: {fileID: 6982812146204527121, guid: 64dce48905ffd9b4293e595fa6941544, type: 3}
Expand Down
22 changes: 22 additions & 0 deletions Basic/ClientDriven/Assets/Scripts/ClientPlayerColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Unity.Netcode;
using UnityEngine;

/// <summary>
/// A script to set the color of each player based on OwnerClientId
/// </summary>

public class ClientPlayerColor : NetworkBehaviour
{
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
SkinnedMeshRenderer m_Renderer = GetComponent<SkinnedMeshRenderer>();

foreach (var material in m_Renderer.materials)
{
// OwnerClientId is used here for debugging purposes. A live game should use a session manager to make sure reconnecting players still get the same color, as client IDs could be reused for other clients between disconnect and reconnect. See Boss Room for a session manager example.
material.SetFloat("_Color_Index", OwnerClientId);
jilfranco-unity marked this conversation as resolved.
Show resolved Hide resolved
}

}
}
11 changes: 11 additions & 0 deletions Basic/ClientDriven/Assets/Scripts/ClientPlayerColor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading