Author Topic: Sync customProperties  (Read 1649 times)

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Sync customProperties
« on: March 08, 2017, 01:06:06 PM »
needed take some customProperties from Tnet.Player

if we can get player, by: Tnet.Player owner = TNManager.GetPlayer(int ID);
how I can get some specific value from player "owner" ?

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Re: Sync customProperties
« Reply #1 on: March 09, 2017, 05:43:10 AM »
or I can do that like this?

  1. public class PlayerController : NetworkBehaviour
  2.     {
  3.  
  4.         public static PlayerController GetPlayer(int aID)
  5.         {
  6.             GameObject[] playerList = GameObject.FindGameObjectsWithTag("Player");
  7.  
  8.             for (int i = 0; i < playerList.Length; i++)
  9.             {
  10.                 if (playerList[i].GetComponent<PlayerController>().m_playerID == aID)
  11.                 {
  12.                     return playerList[i].GetComponent<PlayerController>();
  13.                 }
  14.             }
  15.             return null;
  16.         }
  17. //bla bla bla
  18. }

and use PlayerController.GetPlayer(int aID) - for take Player`s custom Values

it is not good using always "GameObject.FindGameObjectsWithTag"?

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Sync customProperties
« Reply #2 on: March 09, 2017, 09:21:43 AM »
  1. public class PlayerController
  2. {
  3.         public int ID = -1;
  4.        
  5.         void Start()
  6.         {
  7.                 ID = GameManager.Instance.RegisterPlayer(this);
  8.         }
  9. }
  10.  
  11. public class GameManager
  12. {
  13.         public static GameManager Instance;
  14.         List<PlayerController> _Players = new List<PlayerController>();
  15.        
  16.         void Awake()
  17.         {
  18.                 if (Instance != null)
  19.                 {
  20.                         Destroy(this.gameObject);
  21.                 }
  22.                 else
  23.                 {
  24.                         Instance = this;
  25.                 }
  26.         }
  27.        
  28.         public int RegisterPlayer(PlayerController player)
  29.         {
  30.                 _Players.Add(player);
  31.                 return _Players.Count - 1;
  32.         }
  33.        
  34.         public PlayerController GetPlayerByID(int id)
  35.         {
  36.                 if ((id < 0) || (id >= _Players.Count))
  37.                         return null;
  38.                 return _Players[id];
  39.         }
  40. }
  41.