Hi everyone. I’m setting up a game for network play, and am looking to set colors for players as they are added to the game. I’ve been following this guide Unity - Manual: PlayerObjects
I’ve followed the guide to the letter as far as I can tell, but am getting compiler errors on my Player script. I’ve attached the updated version. [57358-player-script.pdf|57358]
I’m also including a screenshot of my game scene. You should be able to see the compiler errors in the console and the inspector tab, which is open to my Player prefab.
Maybe I’m missing something dumb–I’m a Unity noob tbh. Thanks for taking the time.
So as mentioned here http://forum.unity3d.com/threads/error-cs0117-unityengine-quaternion-does-not-contain-a-definition-for-indentity.357564/ the example code Unity provided in the link above is wrong. Quaternion does not recognize "Identity’ as a property…because it’s expecting it in lowercase format. I fixed this and by doing so removed a compiler error. Updated screen attached.
This is the fixed version. Used the code in-line tool since file upload isn’t working. Anyhow, no more compiler errors.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
class Playerr : NetworkBehaviour
{
[SyncVar]
public Color color;
}
class MyManager : NetworkManager
{
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
GameObject player = (GameObject)Instantiate(playerPrefab, new Vector3(0.0f,0.0f,0.0f), Quaternion.identity);
// Compiler throws error when I try setting Playerr's color property = Color.red
Color red = Color.red;
player.GetComponent<Playerr>().color = red;
NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
}
}
This is the fixed version. Used the code in-line tool since file upload isn’t working. Anyhow, no more compiler errors.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
class Playerr : NetworkBehaviour
{
[SyncVar]
public Color color;
}
class MyManager : NetworkManager
{
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
GameObject player = (GameObject)Instantiate(playerPrefab, new Vector3(0.0f,0.0f,0.0f), Quaternion.identity);
// Compiler throws error when I try setting Playerr's color property = Color.red
Color red = Color.red;
player.GetComponent<Playerr>().color = red;
NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
}
}