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 /
avatar image
0
Question by AdeebAwad · Jul 13, 2018 at 05:09 PM · unity multiplayer

Getting Gameobjects in Unet

I am building a multiplayer game where i need the Transform of the object i want to attack so that i can use the LERP function now my problem is getting to those objects beacuse they all share the same script and the only way to defferinciat them from me is through IslocalPlayer ,the objects i want to get consists of players and a spawnable object.

Comment
Add comment · Show 1
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 hexagonius · Jul 13, 2018 at 05:59 PM 0
Share

there must be something that distinguishes even the other players com one another. how are you attacking? all of them at once? I mean you could just create a static list where each of them subscribes on Start and unsubscribes on Destroy. access it, skip the one that is local player and there you go. but usually you would get them by just using physics or something.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Ricna · Jul 17, 2018 at 04:52 AM

Considering your GameObjects already have a script with NetworkBehaviour you can use their netId attribute to identify "yourself" or any other instance. https://docs.unity3d.com/ScriptReference/Networking.NetworkIdentity-netId.html

The isLocalPlayer flag is like a shortcut to do the same thing, but will just verify if the current instance has the same netId. With the netId you can compare any other as you want.

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 Bunny83 · Jul 17, 2018 at 06:03 AM 1
Share

Note that when you send a command to your playerobject you can pass a GameObject referemce as parameter, but only when that gameobject has a NetworkBehaviour attached. When the command is send to the server Unity will automatically send the netId of that object to the server and when the command method is executed on the server it will receive the local instance of that gameobject you originally passed in.


So it's all happening transparently. $$anonymous$$eep in $$anonymous$$d that a client can only send commands to object he has control over. This usually is only the one player object each client has. It's the main communication channel. A client can not send a command to other player objects or objects owned by the server. You need to send the command to your own player object and pass a reference to the object you want to manipulate. When finally executed on the server, the server can decide what to do. The server is allowed to send client RPCs to any objects.

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

88 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

Related Questions

Calling [Command] from an attached NetworkBehaviour does not work? 1 Answer

[C#] Unet spawn dont work. 0 Answers

How to add Multipeer support between iOS and Windows? 0 Answers

Help!How to make own UNet server on the Internet? 0 Answers

How Client send info to Host in Unity Multiplayer 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