Ok, i don’t know exactly what i’m doing wrong, i’m trying to make a client-to-client connection established, you know, than where one is the host and the other the clients?, and the host is also a client too?, yeah that one.
In fact i have a connection done without any dynamicity with visual unity totaly working, an excercise i do before try to do it dynamically using pure-code aproach, which is the one who have the problem right now.
Anyway, i receive this error in the client, when trying to establish the connection:
OnObjSpawn netId: 1 has invalid asset Id UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
and also
OnObjSpawn netId: 2 has invalid asset Id UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
I receive this through the console when i’m trying to connect to the host, it’s important to notice than, in the host, i can see the client “apparead” when the connection is established, BUT, i don’t see none of the elements from the host in the client been shown, i mean, not the scenary, and certainly not the host character, the only thing than the client show are that console errors than i just place before.
Another thing i notice is than every time i go outside of host mode, of the NetworkManagerHUD, the GameObject created for the host is not deleted, so if i press host in the NetworkManagerHUD, and then i stop it, and then i re-press it, i ended up with the original prefab, plus 2 clones, one for each time i press “Host” in the NetworkManagerHUD.
I guess i need to register the prefab, i know than for do that i need to add to the code something like this:
ClientScene.RegisterPrefab (this);
but to be honest i don’t know where exactly i must insert this, i tried in the code inside the prefab of the player, and in the one who generates everything, i’m doing all with code pure aproach, here are the codes:
Controller Class (the one who build the entire world)
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using System.Collections.Generic;
using System;
public class RocketController : NetworkBehaviour {
GameObject someGameObject;
private Dictionary<string, Sprite> DicCharacterSprite;
private UnityEngine.Object emptyObj;
// Use this for initialization
void Awake () {
//Network Manager
someGameObject = new GameObject ("Character2");
this.gameObject.AddComponent<NetworkManager> ();
this.GetComponent<NetworkManager> ().playerSpawnMethod = PlayerSpawnMethod.RoundRobin;
this.gameObject.AddComponent<NetworkManagerHUD> ();
GameObject startingPoint = new GameObject ("startingPoint");
startingPoint.transform.position = new Vector3 (7, 0, 0);
startingPoint.transform.parent = this.transform;
startingPoint.AddComponent<NetworkStartPosition> ();
GameObject startingPoint2 = new GameObject ("startingPoint2");
startingPoint2.transform.position = new Vector3 (-7, 0, 0);
startingPoint2.transform.parent = this.transform;
startingPoint2.AddComponent<NetworkStartPosition> ();
CreateCharacter (someGameObject, new Vector3 (5f, 0f, 0f), "CharacterPlus", "Character2");
//Destroy (GameObject.Find("Character2(Clone)"));
this.GetComponent<NetworkManager> ().playerPrefab = Instantiate (someGameObject) as GameObject;
}
bool CreateCharacter(GameObject goConv, Vector3 vecAwake, string doango, string name){
try
{
DicCharacterSprite = LoadSprites ();
System.Type type = System.Type.GetType (doango);
//Rigidbody2D and Script
goConv.AddComponent<Rigidbody2D> ().gravityScale = 0;
goConv.AddComponent (type);
//Spŕite Renderer
goConv.AddComponent<SpriteRenderer>();
Sprite newSprite;
DicCharacterSprite.TryGetValue("índice", out newSprite);
goConv.GetComponent<SpriteRenderer>().sprite = newSprite;
//Network Identity
goConv.AddComponent <NetworkIdentity> ();
goConv.GetComponent <NetworkIdentity>().localPlayerAuthority = true;
//Network Transform
goConv.AddComponent<NetworkTransform> ();
return true;
}
catch(Exception ex) {
Debug.Log (ex.ToString ());
return false;
}
}
Dictionary<string, Sprite> LoadSprites(){
DicCharacterSprite = new Dictionary<string, Sprite> ();
Sprite[] sprites = Resources.LoadAll<Sprite> ("Sprites");
//Debug.Log ("LOADED RESOURCE: CharacterSprite");
Debug.Log ("Speak Your Mind! (LOADED SPRITES)");
foreach (Sprite sprs in sprites) {
Debug.Log (sprs.name);
DicCharacterSprite [sprs.name] = sprs;
}
return DicCharacterSprite;
}
}
PlayerSetup (it set some component relation of the character)
using UnityEngine;
using UnityEngine.Networking;
public class PlayerSetup : NetworkBehaviour {
[SerializeField]
Behaviour[] componentsToDisable;
void Start()
{
if (!isLocalPlayer) {
for (int i = 0; i < componentsToDisable.Length; i++) {
componentsToDisable *.enabled = false;*
-
}*
-
} else {*
-
GameObject.Find ("SceneCamera").GetComponent<Camera> ().enabled = false;*
-
GameObject.Find ("SceneCamera").GetComponent<AudioListener> ().enabled = false;*
-
GameObject.Find ("CameraPlayer").GetComponent<Camera> ().enabled = true;*
-
GameObject.Find ("CameraPlayer").GetComponent<AudioListener> ().enabled = true;*
-
}*
-
}*
-
void OnDisable()*
-
{*
-
//Maybie, if the player dies, well need to place something*
-
}*
}
Any help, constructive comment, question or answer would be much apreciated.
Thanks in advance.