Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Network Spawning Prefabs 0 Answers

Client-Server architecture 0 Answers

Unity network manager assign playerprefab at runtime 0 Answers

Client choice of prefabs on a NetworkLobbyManager 0 Answers

HELP! Both players rotate their cameras towards the same direction?? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges