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
1
Question by vanshika1012 · Mar 03, 2016 at 12:38 PM · networkingspawnnetworkplayernetwork instantiate

NetworkServer is not active. Cannot spawn objects without an active server.

Hi,

I am trying to implement a multiplayer feature. Its like a snake game, snake eats food and generate its part. I can successfully generate food and part as well but its not moving and giving me error "NetworkServer is not active. Cannot spawn objects without an active server."

Here is my code :-

   private void CmdCheckForFood(Vector3 snakePartPosToBeInitialize,Vector3 headPos)
 {
     
     if(_food != null)
     {
         if (_food.transform.position == headPos) // if food collide with head. 
         {
             _food.transform.position = GenerateRandomPosForFood(); 
                currPartOfSnake += 1;
             CmdCreatePartSnake(snakePartPosToBeInitialize);


         }
     }
     
 }
 public void CreatePartSnake(Vector3 snakePartPosToBeInitialize)
 {
     GameObject obj = Instantiate(snakePart, snakePartPosToBeInitialize, Quaternion.identity) as GameObject;

     obj.name = "" + currPartOfSnake;
     obj.transform.parent = gameObject.transform;
     tail.Add(obj); // tail is list which contain all part of snake
     NetworkServer.Spawn(obj);
 }
Comment
Add comment · Show 2
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
avatar image Guhanesh · Mar 03, 2016 at 12:49 PM 0
Share

can you add movement script too?

avatar image vanshika1012 Guhanesh · Mar 04, 2016 at 11:14 AM 0
Share

Here is my movement Code :-

     private void CmdUpdate$$anonymous$$ySnakePos()
     {
     //try{
     if(HeadTransform == null)
         return;
     Vector3 parentPos = HeadTransform.position;
     Vector3 headNextPos = HeadTransform.position + nextStep;
     if (headNextPos.x > maxX)
     {
         headNextPos.x = $$anonymous$$X;
     }
     else if (headNextPos.x < $$anonymous$$X)
     {
         headNextPos.x = maxX;
     }
     else if (headNextPos.y > maxY)
     {
         headNextPos.y = $$anonymous$$Y;
     }
     else if (headNextPos.y < $$anonymous$$Y)
     {
         headNextPos.y = maxY;
     }
 
     HeadTransform.position = headNextPos;
     int count = gameObject.transform.childCount;

     List<GameObject> snakeParts = new List<GameObject>();
     for (int i = 0; i < count; i++)
     {
         GameObject obj = gameObject.transform.GetChild(i).gameObject;
         snakeParts.Add(obj);
     }


     Vector3 lastPos = new Vector3(0,0,0);
     Debug.Log("tail count"+tail.Count);
     for (int i = 0; i < tail.Count; i++)
     {
         Vector3 currPos = tail[i].transform.position;
         if (i == tail.Count - 1)
         {
             lastPos = currPos;
         }
         tail[i].transform.position = parentPos;
         parentPos = currPos;
     }
     CheckForCollision(headNextPos);
     CmdCheckForFood(lastPos,HeadTransform.position);
 }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Networking concept and spawning questions 1 Answer

Not able to instantiate an object on the Client using [Command] UNET 0 Answers

UNET : random bugs with spawning 0 Answers

Multiplayer shows different scenes 1 Answer

[uNET] Network objects spawned not spawn in new clients 1 Answer


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