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 thetemplar · Dec 03, 2014 at 07:37 PM · multiplayerrts

Multiplayer RTS Script

Hello everyone,

I am currently building my own RTS and now am stuck with the management of different players.

I couldn't get any information on how to do this the best way, so I am kind of helpless. I thought I instantiate a GameObject for every connected player. All his Units and Buildings are a children of this Object to easily determine its owner. But to achiev this, I need to make sure then these objects are on every client the same state.

How do I do this or is there even a better way?

Edit: I know the basics like: http://www.paladinstudios.com/2013/07/10/how-to-create-an-online-multiplayer-game-with-unity/

Its more about how to create units/buildings and assign them to players, so that its on every client the same.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GraviterX · Dec 04, 2014 at 12:23 AM

Try attaching the units to the player in the hierarchy and then saving them as a prefab. For my games I've been working with Photon Cloud. It's a free plugin in the asset store. Here is a link to a tutorial I found : https://www.youtube.com/watch?v=mLAilMkRxYU. This tutorial also guides you through a script that instantiates the prefab for every new connected player. Hope this helps.

Comment
Add comment · Show 1 · 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 thetemplar · Dec 04, 2014 at 01:54 AM 0
Share

Thanks. But still, the main problem I have is to make a game-wide list of all players and their gameobject right at the start.

avatar image
0

Answer by jpthek9 · Dec 05, 2014 at 01:38 AM

That might get very messy, Graviter. You should instead create a script that controls the player: his status (dead or alive) and possibly number of upgrades. Instantiate this for everyone and use an RPC to set its unique player number (I.e. Player 1's controller gets 1).

Put an extra RPC function on all the spawned units that gets called when they're instantiated. To make everything clean in neat, this function can also set the unit's stats and turns on all needed scripts, but the main thing is that you call the RPC with a certain integer representing its player. You use this integer to find the controller that has the ID of the same integer. Maybe even add the unit to the player controller's list for greater control and less bandwidth usage.

This solution has the added benefit of being able to call a single RPC on the player controller for upgrading a player's units.

I.e. in the RTS game I'm working on there are 8 players. If player 1 spawns a unit, that unit gets an RPC targeted for everyone, and on everyone's client it finds its player controller. If player 1's base gets destroyed, an RPC gets called on itself for everyone and on everyone's client, all units contained in its list are destroyed. If I upgrade my units, the upgrade goes through the player controller and calls an RPC that tells all other instances of itself on others' clients to let all units in the player controller's list know to be upgraded.

Okay this may get very messy as well but it's the same concept and lets you use list access for everything.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

RTS Multiplayer Model 2 Answers

RTS Multiplayer, Lock-step simulations and fixed game timings 1 Answer

Is a Unity simulation deterministic? 4 Answers

Time problem with Joining to Multilayer game 1 Answer

Multiplayer Chat Script (Problem : mixed names) 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