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 qasem2016 · Aug 21, 2017 at 05:43 PM · playernetworklocal

solution to my problem . need your experience in unet

hi . i create a 1 v 1 online game . in that game there is a button that score up the player (button is in ui canvas not in player prefab) . here is the code :

 public void ClickMe() {
    GameObject Player = GameObject.FindGameObjectWithTag ("Player");
    if (Player != null) {
       Score score = Player.GetComponent<Score> ();
       score.ScoreUP (10);
    }
 }

the "Player" tag set in OnStartLocalPlayer function in my playercontroller.cs file on player prefab :

 public override void OnStartLocalPlayer() {
    this.transform.tag = "Player";
 }

for some reason i cant use OnStartLocalPlayer function !

how can i run ScoreUP function in ClickMe button only on who click it ?

Comment
Add comment · Show 3
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 christoph_r · Aug 21, 2017 at 07:03 PM 0
Share

You need to word your questions more clearly. What does "I can't use" mean? And what exactly does your last question mean? We have no idea about your project and what you're trying to do (1v1 online game) does not help. And how does unet tie into everything?

avatar image qasem2016 christoph_r · Aug 22, 2017 at 01:53 PM 0
Share

i use a plugin that OnStartLocalPlayer function dose not work with it

1 v 1 is a pnalty game !

i want to change local player tag without using OnStartLocalPlayer !

avatar image unidad2pete qasem2016 · Aug 24, 2017 at 02:58 PM 1
Share

You cant use only OnStartLocalPlayer? Or you cant use NetworkIdentity? If you have NetworkIdentity only needs check if is local whenever you want.

 void Start()
 {
      if(isLocalPlayer)
      {
           // code...
      }
 }

Without NetworkIdentity maybe you can makes a string, with your nick for example, before to connect on a simple menu with an InputField, and then when you are connected, check if(StringName==StringName) That could work, I dont know.

1 Reply

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

Answer by qasem2016 · Aug 26, 2017 at 07:18 AM

i solve it !

 public void ClickMe() {
     GameObject[] Ps = GameObject.FindGameObjectsWithTag ("Player");
     Players.AddRange (Ps);
     for (int i = 0; i < Players.Count; i++) {
         MyPlayerController PC = Players [i].GetComponent<MyPlayerController> ();
         if (PC.hasAuthority) {
             Score score = Players [i].GetComponent<Score> ();
             score.ScoreUP (10);
         }
     }
 }

this is the code in my button . all player prefabs (i just have 2) have "Player" tag !

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 qasem2016 · Aug 26, 2017 at 07:19 AM 0
Share

Players variable is a list : public System.Collections.Generic.List Players = new System.Collections.Generic.List();

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

96 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

Related Questions

Photon camera problum 0 Answers

Unity server/client player attachments parenting 1 Answer

How to use NetworkServer.ReplacePlayerForConnection() to give a player control over another player object 0 Answers

How to create and set different Player ID's to individual controllers? 1 Answer

how to spawn a player prefab on a server 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