Question by 
               Obsdark · Nov 24, 2016 at 06:12 PM · 
                networkingprefabcharactergenerationdynamically  
              
 
              Is it possible to use Dinamicaly generated characters instead of prefabs in/for NetworkManager?
That's the question, here i have the code where i generate both, Networkmanager and the dinamicaly generated characters.
Idealy, i want to have one of this dinamicaly generated characters, but i failed to make it work with the NetworkManager, mostly because of the "prefab" requeriment, i don't want to save a prefab to save them and then dinamize them, is there any way i can archieve this?
Here is the code:
 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 using System.Collections.Generic;
 
 public class CharacterSpriteCreator : NetworkBehaviour {
 
     // Use this for initialization
     private Dictionary<string, Sprite> DicCharacterSprite;
 
     GameObject newGameObject;
 
     void Start () {
         newGameObject = CreateCharacter (new Vector3 (5f, 0f, 0f), "CharacterPlus", "Character2");
 
         GameObject go = new GameObject("NetworkManager");
         go.AddComponent<NetworkManager> ().playerSpawnMethod = PlayerSpawnMethod.RoundRobin;
 
         go.GetComponent<NetworkManager> ().playerPrefab = Instantiate(newGameObject);
 
         go.AddComponent<NetworkManagerHUD> ();
 
         GameObject startingPoint = new GameObject("startingPoint");
         startingPoint.transform.position = new Vector3 (50,0,1);
         startingPoint.transform.parent = go.transform;
         startingPoint.AddComponent<NetworkStartPosition> ();
 
         GameObject startingPoint2 = new GameObject("startingPoint2");
         startingPoint2.transform.position = new Vector3 (-50,0,1);
         startingPoint2.transform.parent = go.transform;
         startingPoint2.AddComponent<NetworkStartPosition> ();
 
 
         //GameObject.Find ("Head").AddComponent<Sprite> ("ThisIsYou");
     }
 
 
     // Update is called once per frame BUT HERE IS NOT IN USE!!!
 
     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);
             DicCharacterSprite [sprs.name] = sprs;
         }
 
         return DicCharacterSprite;
     }
 
     GameObject CreateCharacter(Vector3 vecAwake, string doango, string name){        
         DicCharacterSprite = LoadSprites ();
 
         System.Type type = System.Type.GetType (doango);
         GameObject go = new GameObject(name);
 
         go.transform.SetParent (this.transform, true);
         //go.transform.position = vecAwake;
         go.name = doango;
 
         GameObject head = new GameObject ("Head");
         GameObject body = new GameObject ("Body");
 
         head.AddComponent<SpriteRenderer> ().sprite = DicCharacterSprite["ThisIsYou"];
         body.AddComponent<SpriteRenderer> ().sprite = DicCharacterSprite["RandyWeb"];
 
         head.transform.localPosition = new Vector3(head.transform.position.x+.225f, (head.transform.position.y + 1.15f), head.transform.position.z);
         body.transform.localScale = new Vector3(0.6f,0.6f,0);
 
         head.transform.SetParent (go.transform);
         body.transform.SetParent (go.transform);
 
         go.AddComponent<Rigidbody2D> ().gravityScale = 0;
         go.AddComponent (type);
         go.AddComponent <NetworkIdentity> ().localPlayerAuthority = true;
 
         return go;
     }
 }
Any constructive comment, request for clarification or suggestion would be very welcome too.
thanks in advance
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                