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 TheSorm · May 06, 2016 at 12:26 PM · c#networkingplayernetworkhost

How can i acess the local Player from Script

I have a Network game and there are a few Scripts who call the Player Script in theier Start() Methods. Looks like this:

 void Start () {

     FirstPersonController fpc = GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>();
     int i = fpc.GetSecToMax();
 }

But in an Network Game there are Multiple Players and i want to know how i can just enter the Local Player (this script work on the Host Player but not on Client Players)

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
3
Best Answer

Answer by meat5000 · May 06, 2016 at 12:28 PM

isLocalPlayer

Comment
Add comment · Show 7 · 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 TheSorm · May 06, 2016 at 12:53 PM 0
Share

funny you ... if i check if it is the local player WOH CALL this $$anonymous$$ethod aniway i dont know what Player on the server is my local PLayer

avatar image meat5000 ♦ TheSorm · May 06, 2016 at 02:11 PM 1
Share

Erm, no. Serious me :P

You put this in your code and it will only run on a Client for an object which is its own player. Dont forget that the exact same script will run on all machines and you have to put in these attributes to tell the script what it can and cant run.

A host machine will run both server and client code, treating the client in the same way as remote clients, in essence.

Your server does not have a player, for itself. The client on the server does.

A method which I use, which also utilises the isLocalPlayer attribute is during your Player Setup script, which should run first when a new Player is added to the scene, detect if the player is local or not and then Change the Tag of the player to RemotePlayer if !isLocalPlayer. The tags of each object do not seem to sync across the network so will happily read differently on each client. This enables you to use

 GameObject.FindGameObjectWithTag("Player")

Scripts which use the isLocalPlayer attribute can benefit from labelling the respective functions youve created with the [Client] attribute to make sure the server doesn't attempt to run the code at all. This is necessary for the client on the host machine.

avatar image TheSorm meat5000 ♦ · May 06, 2016 at 03:08 PM 0
Share

ok that is working perfect, Thanks :) but the scripts are for chaging somethings on a canvas in the sean but the one thing is only shown at the host player and the other thing only at the client ... Is it good to have one Canvas for the HUD in the Game Scean and all player use this Convas ? Or how shult i do that ?

Show more comments
Show more comments

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

162 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 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

Network Game Player reference 0 Answers

Command method dont change variables on server 0 Answers

What is the CCU of the default Unity Networking? 1 Answer

NetworkManager.OnServerDisconnect not being called 2 Answers

Network call Method from Instants of Prefab 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