Answered step by step
Verified Expert Solution
Question
1 Approved Answer
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using NETWORK _ ENGINE; public class DicePlayer : NetworkComponent { public Text Dice; public InputField NameField; public
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using NETWORKENGINE;
public class DicePlayer : NetworkComponent
public Text Dice;
public InputField NameField;
public Button RollButton;
public override void HandleMessagestring flag, string value
public override void NetworkedStart
ifIsLocalPlayer
NameField.interactable false;
RollButton.interactable false;
public void UISetNamestring s
public void UIRoll
public override IEnumerator SlowUpdate
whileIsConnected
ifIsServer
ifIsDirty
IsDirty false;
yield return new WaitForSecondsf;
Start is called before the first frame update
void Start
GameObject temp GameObject.FindGameCanvas;
iftemp null
throw new System.ExceptionERROR: Could not find game canvas on the scene.";
else
this.transform.SetParenttemptransform;
Update is called once per frame
void Update
Phase : Minutes
Using the script: DicePlayer, UISetName implements the code to send their name as a string.
a The server will store the player name and then return the value for the client.
bFeel free to check for empty strings
The server will not respect the roll command from the player until they have entered a name.
Disable the roll button until the name is set on the client side, but ONLY for the local player.
Note: It is already disabled for the nonlocal players.
Make sure the nonlocal player clients see the name in the input field.
Phase : Minutes
Use the DicePlayer.UIRoll function allows the local player to request the server roll sixsided
dice Random integer between and
The server will acknowledge the requests to all the clients; HOWEVER, the server will not send a
random number for second.
During the delay between the acknowledgment and the random number, each client will flash a
random number between and in the appropriate Dice text field.
a This random number will be updated every seconds until the servers random
number is received. Hint: SlowUpdate
b These random numbers simulate rolling the dice.
c These random numbers do not need to be synchronized as they are a graphical
component only.
Once the clients receive the random number from the server, that value will be displayed in the
Dice text box.
The local player can then request another roll.
a Note: All clients should see each other's dice randomly flashing, waiting for the
server to provide a value.
b All clients should see the final value given by the server.
Phase : minutes
Inside slow update setup the IsServerIsDirty template.
a Any player who joins late should see the last roll and the name of all the other
players.
b As the state is too transient to worry about, I will not test for a client joining while
the dice is rolling.
Make sure IsDirty is set to false after updating
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started