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
0
Question by Willbl3pic · Feb 17, 2016 at 08:27 PM · c#networkingmultiplayermultiplayer-networkingmultiplayer networking

How to find local player gameobject? c#

So I have a UI that pops up and the player selects from two teams. When a player clicks one of the buttons, it then runs a function on a script, which is then supposed to set some variables, then run another script, on the local player, which then instantiates the appropriate weapons. How would I find which player the local player is? Alternatively, how could I make a UI button OnClick() event do something on the player?

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

3 Replies

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

Answer by Willbl3pic · Feb 17, 2016 at 10:45 PM

Never mind, I'll just work around it by getting the player GameObject to do it all itself. I don't know why I didn't do that in the first place.

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
avatar image
0

Answer by Salmjak · Feb 17, 2016 at 08:46 PM

Just use "`if(isLocalPlayer)`". Then the script will only run on the local player.

Comment
Add comment · Show 5 · 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 Willbl3pic · Feb 17, 2016 at 08:55 PM 0
Share

Yes, but the script does not run on the player.

avatar image Salmjak Willbl3pic · Feb 17, 2016 at 09:15 PM 1
Share

@Willbl3pic Then it depends on what you mean by "local player". Any client is in itself the local player.

You really have to give us more info. How does the script not run on the local player? Do you use a if(isServer) check in the script? Do you use [Command] or [ClientRpc]? What are the variables that are going to change? Why can't you use [Command] + [SyncVar]?

In any case I'm sure you can use the $$anonymous$$essage class.

avatar image Willbl3pic Salmjak · Feb 17, 2016 at 09:30 PM 0
Share

By the local player I mean the GameObject which the player is controlling.

Show more comments
avatar image Firedan1176 Willbl3pic · Feb 17, 2016 at 09:25 PM 0
Share

Salmjak has the right idea, you need to give us more information. What do you mean

it does not run on the player?

avatar image
0

Answer by Integrational · Jan 11, 2018 at 02:34 PM

@Willbl3pic Use a for loop to go through every instance of an active GameObject of tag "Player" (GameObject.FindGameObjectsWithTag("Player")), and while in the for loop, get the network identity component on the GameObject of index i, and check if the isLocalPlayer variable on that component is true. If so, then the GameObject of index i is your local player character.

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

76 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

Related Questions

UNET Clients Laggy 0 Answers

How to decide an asynchronous multiplayer solution for a turn based mobile chess game? 0 Answers

Locally disabling GameObjects with network transform components attached. 1 Answer

UNET NetIDs for Scene Objects Mismatched Between Client and Server 1 Answer

Unity Networking Cannot Join Match - Room Disappears 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