Answered step by step
Verified Expert Solution
Link Copied!

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 NETWORK_ENGINE;
public class DicePlayer : NetworkComponent
{
public Text Dice;
public InputField NameField;
public Button RollButton;
public override void HandleMessage(string flag, string value)
{
}
public override void NetworkedStart()
{
if(!IsLocalPlayer)
{
NameField.interactable = false;
RollButton.interactable = false;
}
}
public void UI_SetName(string s)
{
}
public void UI_Roll()
{
}
public override IEnumerator SlowUpdate()
{
while(IsConnected)
{
if(IsServer)
{
if(IsDirty)
{
IsDirty = false;
}
}
yield return new WaitForSeconds(.1f);
}
}
// Start is called before the first frame update
void Start()
{
GameObject temp = GameObject.Find("GameCanvas");
if(temp == null)
{
throw new System.Exception("ERROR: Could not find game canvas on the scene.");
}
else
{
this.transform.SetParent(temp.transform);
}
}
// Update is called once per frame
void Update()
{
}
}
Phase 1: (10 Minutes)
1. Using the script: DicePlayer, UI_SetName 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.
b.(Feel free to check for empty strings)
2. The server will not respect the roll command from the player until they have entered a name.
3. Disable the roll button until the name is set on the client side, but ONLY for the local player.
4. Note: It is already disabled for the non-local players.
5. Make sure the non-local player clients see the name in the input field.
Phase 2: (15 Minutes)
1. Use the DicePlayer.UI_Roll function allows the local player to request the server roll six-sided
dice (Random integer between 1 and 6).
2. The server will acknowledge the requests to all the clients; HOWEVER, the server will not send a
random number for 1 second.
3. During the delay between the acknowledgment and the random number, each client will flash a
random number between 1 and 6 in the appropriate Dice text field.
a. This random number will be updated every .1 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.
4. Once the clients receive the random number from the server, that value will be displayed in the
Dice text box.
5. 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 3: (15 minutes)
1. Inside slow update setup the IsServer/IsDirty 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.
2. Make sure IsDirty is set to false after updating

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions