Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by 5114fu · Sep 10, 2013 at 02:17 AM · networkserverrpcclientnetwork.instantiate

Spawning Clients

I make a multiplayer game with max 4 Players (1 Server + 3 Clients). I have four different spawn-positions. The Server takes the first spawn-position. The first Client shoult take the next spawn-position, the seceond client the next spawn-position, etc. With my code, all Clients spawn at the first postion. Why?

 [System.Serializable]
 public class SpawnPoint
 {
     SpawnPoint()
     {
         isAvailable = true;
     }
 
     public Transform transform;
     public GameObject playerPrefab;
     public bool isAvailable;
 }
 
 public class SpawnManager : MonoBehaviour
 {
     public SpawnPoint[] spawnPoint = new SpawnPoint[4];
 
     private int m_playerCount = 0;
 
     void OnServerInitialized()
     {
         Network.Instantiate(spawnPoint[0].playerPrefab, spawnPoint[0].transform.position, spawnPoint[0].transform.rotation, 0);
         spawnPoint[0].isAvailable = false;
     }
 
     void OnPlayerConnected(NetworkPlayer player)
     {
         networkView.RPC("PlayerCount", RPCMode.Others, Network.connections.Length);
     }
 
     void OnConnectedToServer()
     {
         SpawnPlayer(m_playerCount);
     }
 
     void SpawnPlayer(int index)
     {
         Network.Instantiate(spawnPoint[index].playerPrefab, spawnPoint[index].transform.position, spawnPoint[index].transform.rotation, 0);
     }
 
     [RPC]
     void PlayerCount(int value)
     {
         m_playerCount = value;
     }
 }

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 getyour411 · Sep 10, 2013 at 04:08 AM 0
Share

Is your syntax on line 28 correct? You have networkView the doc shows it as NetworkView - I don't know multiplayer stuff so that might be irrelevant.

avatar image 5114fu · Sep 10, 2013 at 08:35 AM 0
Share

That should be fine. NetworkView is the data type. networkView is the variable form type NetworkView. I think the Problem is, that the Client is Spawning before he(it? sorry my english sucks) get the Information from the RPC call.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by 5114fu · Sep 10, 2013 at 10:18 AM

Solved it without RPC call:

[System.Serializable] public class SpawnPoint { SpawnPoint() { isAvailable = true; }

 public Transform transform;
 public GameObject playerPrefab;
 public bool isAvailable;

}

public class SpawnManager : MonoBehaviour { public SpawnPoint[] spawnPoint = new SpawnPoint[4];

 private int m_playerCount = 0;

 void OnServerInitialized()
 {
     Network.Instantiate(spawnPoint[0].playerPrefab, spawnPoint[0].transform.position, spawnPoint[0].transform.rotation, 0);
     spawnPoint[0].isAvailable = false;
 }

 void OnConnectedToServer()
 {
     SpawnPlayer(int.Parse(Network.player.ToString()));
 }

 void SpawnPlayer(int index)
 {
     Network.Instantiate(spawnPoint[index].playerPrefab, spawnPoint[index].transform.position, spawnPoint[index].transform.rotation, 0);
 }

}

Comment
Add comment · Share
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

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

15 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

Related Questions

RPC is called but it doesn't destroy some GameObject instances 1 Answer

RPC Call Mix Up Issues 0 Answers

Deleteing Objects created by Clients 0 Answers

Get RPC senders ID, or IP? 1 Answer

Network.Instantiate dont instantiate object 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