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 potu1304 · Jun 02, 2012 at 01:54 PM · multiplayernetworkshooterspawner

Different Player Colours (Multiplayer)

Hello! I try to make a simple Multiplayer FPS Game with up to 6 Players. I have a simple spawner but I want to have a spawner which spawns players with different colours.(So 6 different colours) Here is my spawner

 using UnityEngine;
 
 using gui = UnityEngine.GUILayout;
 
 
 
 public class GameMenu : MonoBehaviour
 
 {
 
     public GameObject PlayerPrefab;
 
     string ip = "127.0.0.1";
 
     
 
     public void Awake()
 
     {
 
         Application.runInBackground = true;
 
     }
 
 
 
     public void CreatePlayer()
 
     {
 
         connected = true;
 
         var g = (GameObject)Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 1);
 
         g.networkView.stateSynchronization = NetworkStateSynchronization.Unreliable;
 
         g.camera.enabled = true;
 
         camera.enabled = false;
 
     }
 
     void OnDisconnectedFromServer()
 
     {
 
         connected = false;
 
     }
 
     void OnPlayerDisconnected(NetworkPlayer pl)
 
     {
 
         Network.DestroyPlayerObjects(pl);
 
     }
 
     void OnConnectedToServer()
 
     {
 
         CreatePlayer();
 
     }
 
     void OnServerInitialized()
 
     {
 
         CreatePlayer();
 
     }
 
     bool connected;
 
     void OnGUI()
 
     {
 
         if (!connected)
 
         {
 
             ip = gui.TextField(ip);
 
             if (gui.Button("connect"))
 
             {
 
                 Network.Connect(ip, 5300);
 
             }
 
             if (gui.Button("start"))
 
             {
 
                 Network.InitializeServer(10, 5300, false);
 
             }
 
         }
 
     }
 
 }

Should I add 6 different player prefabs to the project? If yes, how do I let them spawn in a row, if the first player connects the (blue) player 1 spawns? Can somebody help me out?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ExTheSea · Jun 02, 2012 at 02:28 PM

You could probably use Network.connections.length with the 6 prefabs.

It would be something like this I think:

 public GameObject FirstPrefab;
 public GameObject SecondPrefab;
 ...

 void OnConnectedtoServer(){
 switch(Network.connections.length){
     case(1)
       CreatePlayer(SecondPrefab);//you would have chance the function to CreatePlayer(GameObject PlPref)...
     case(2)
       CreatePlayer(ThirdPrefab);
     ....
 }

 void OnServerInitialized()
 {
 CreatePlayer(FirstPrefab);
 }

Maybe you don't even need to make 6 prefab. Maybe you can change between different materials/textures.

I hope my answer gives you an idea.

Comment
Add comment · Show 4 · 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
avatar image potu1304 · Jun 02, 2012 at 06:25 PM 0
Share

Yes thats an good idea, but isn't i a fault to have more than one CreatePlayer?

avatar image ExTheSea · Jun 02, 2012 at 06:47 PM 0
Share

what do you mean? CreatePlayer(...) gets only called ones per player who connects to the server. Do you know how switch-case works?

avatar image potu1304 · Jun 02, 2012 at 06:52 PM 0
Share

Oh and what do you mean with PlPref?

avatar image ExTheSea · Jun 02, 2012 at 07:42 PM 0
Share

I mean need to change your CreatePlayer to something like:

CreatePlayer(GameObject PlPref)

PlPref is just a variable in this case so you can access the different prefabs when you instantiate the player. Do you understand what i want to say?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Erro in MultiPlayer 0 Answers

Multiplayer Walk animation playing for opposite person 0 Answers

Change networkView owner not working 1 Answer

Bleeding and Health Generation Skript 1 Answer

How can I instantiate different prefabs for owner and proxy using photon? 2 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