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 ?
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?
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 !
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.
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 !
Players variable is a list : public System.Collections.Generic.List Players = new System.Collections.Generic.List();