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 /
This question was closed Sep 07, 2018 at 02:40 PM by lastjanissary for the following reason:

Too subjective and argumentative

avatar image
0
Question by lastjanissary · Sep 03, 2018 at 06:05 PM · scripting problemsync

Networking Buttons and Syncvar

Hello everybody,

I'm developing a turn based game. My question is very simple. I have a button (currently as a scene object and canvas its attached to has network identity) and this button has a scrip attached. When player clicks on it, it generates random number like rolling dice. I'm using syncvar but I cannot make player objects to get this random number generated.

Below is my code attached to UI button as a part of scene;

 public class Roll_Dice : NetworkBehaviour
 {
     [SyncVar] public int newDice_Score;
     public int Dice_Score;
     public Text Dice_Text;
     public GameObject BoardManager;
     public Button RollDice;
     public bool PlayerTurn = false;
 
 
 
     void Start()
     {
 
         RollDice.gameObject.SetActive(true);
         Dice_Text.text = " ";
         BoardManager.gameObject.SetActive(true);
         Button btn1 = RollDice.GetComponent<Button>();
         btn1.onClick.AddListener(TaskOnClick);
 
     }
 
 
 
     public void TaskOnClick()
     {       
         Dice_Score = Random.Range(2, 13);
         CmdDiceScore(Dice_Score);
         
         Dice_Text.gameObject.SetActive(true);
         Dice_Text.text = "Rolled" + " " + newDice_Score;
          Invoke("Close_Dice_Roll", 3);
 
 
 
     }
 
     [Command]
     void CmdDiceScore(int Dice_Score)
     {
         newDice_Score = Dice_Score;
         RpcDiceScore(Dice_Score);
     }
 
     [ClientRpc]
     void RpcDiceScore(int Dice_Score)
     {
         newDice_Score = Dice_Score;
         Debug.Log("RPC");
 
     }
 
     public void Close_Dice_Roll()
     {
         Dice_Text.gameObject.SetActive(false);
         RollDice.gameObject.SetActive(true);
         PlayerTurn = !PlayerTurn;
         
     }    
     
 }


And, below is attached to player object.

 public class Roll_DicePlayer : NetworkBehaviour {
 
     public Text Dice_Text;
     public GameObject PlayerCanvasClone;
     [SyncVar] public int newDice_Score;
     
     public GameObject Dice_Button;
 
     public override void OnStartLocalPlayer()
     {
 
        
 
     }
 
 

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

  • Sort: 
avatar image
0

Answer by myzzie · Sep 03, 2018 at 07:52 PM

You don't need a syncvar if you're going to send it through an rpc and vice versa. With the syncvar, you only have to change the variable and the client's same variable will change.

Your Roll_DicePlayer class has nothing to do with the above code, not sure why you put it there.

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 lastjanissary · Sep 04, 2018 at 03:21 PM 0
Share

Still Syncvar value doesnt update on player object;

Below are Syncvar values in Dice_Button and PlayerConnection object. alt text

button.png (102.1 kB)
player.png (108.6 kB)

Follow this Question

Answers Answers and Comments

159 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

Related Questions

How to synrchonize two floats from different scripts? 1 Answer

How to Sync between Clinet->Server? (Mirror) 0 Answers

How to Sync Spine Skins on UNet 0 Answers

Enabling multiple Monobehaviour Components in a game object 1 Answer

How could I center a GUI box on screen? 3 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