Question

In: Computer Science

In Unity with C#, I need to implement a dice simulator in my character generator(D&D). I...

In Unity with C#, I need to implement a dice simulator in my character generator(D&D). I have 6 sides of UI images(2D). With my code, I am able to roll and get the number in my console text(randomly).

But, I need help for rolling 5 dices, not the 1 dice. Also, I need to add all the three highest rolls with 5 dices and get a result in my display.

Ex) 1. Players must roll 5d6 and add the three highest rolls to compute each of the six Abilities. Note make all modifiers default to +2.

Solutions

Expert Solution

using UnityEngine;

using UnityEngine.UI;

using System;

using System.Collections;

public class diceRoller : MonoBehaviour

{

public int numberDice;

public int sidesDice;

public int modifierDice;

public InputField numDice;

public InputField sidesDice;

public InputField diceModifier;

public Text outputText;

System.Random ranDice = new System.Random();

void Start()

{

numDice = numDice.GetComponent<InputField>();

sidesDice = sidesDice.GetComponent<InputField>();

diceModifier = diceModifier.GetComponent<InputField>();

outputText = outputText.GetComponent<Text>();

}

public void RollDice()

{

numberDice = Convert.ToInt32(numDice.text);

sidesDice = Convert.ToInt32(sidesDice.text);

modifierDice = Convert.ToInt32(diceModifier);

int counter = numberDice;

while (counter > 0)

{

int randomNum = randDice.Next(1, sidesDice);

outputText.text = outputText.text + Environment.NewLine + "You Rolled 1D" + sidesDice + "+" + modifierDice + " for " + randomNum + ". Your result is " + (randomNum + modifierDice);

counter = (counter - 1);

}

}

}


Related Solutions

I need to,  Modify my mapper to count the number of occurrences of each character (including punctuation...
I need to,  Modify my mapper to count the number of occurrences of each character (including punctuation marks) in the file. Code below: #!/usr/bin/env python #the above just indicates to use python to intepret this file #This mapper code will input a line of text and output <word, 1> # import sys sys.path.append('.') for line in sys.stdin: line = line.strip() #trim spaces from beginning and end keys = line.split() #split line by space for key in keys: value = 1 print...
I need implement the operation bellow. Please add comment on some lines to compare with my...
I need implement the operation bellow. Please add comment on some lines to compare with my code. The program will implement the following operations on the Matrix class: 1. Matrix addition 2. Matrix subtraction 3. Matrix multiplication 4. Matrix scalar multiplication 5. Matrix transpose Vector class will implement the following operations: 1. Vector length 2. Vector inner (dot product) 3. Vector angle Vector 3D Class The class Vector3D is derived from the Vector class, and it implements a vector in...
I need this in C# with pseudocode Exercise #2: Design and implement a programming (name it...
I need this in C# with pseudocode Exercise #2: Design and implement a programming (name it EvenOdd) that uses a while loop to determine and print out all even numbers between 50 and 100 on a single line, separated by commas. Then another while loop in the same program to print out all odd numbers between 50 and 100 on a new line, separated by commas. Document your code and properly label the outputs as shown below. Even numbers between...
I have A B and C answered I only need the answer to D and E....
I have A B and C answered I only need the answer to D and E. I have included the correct answers for A B and C Problem 8-41 (LO. 2, 3, 9) Lori, who is single, purchased 5-year class property for $200,000 and 7-year class property for $400,000 on May 20, 2016. Lori expects the taxable income derived from her business (without regard to the amount expensed under § 179) to be about $800,000. Lori wants to elect immediate...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following:...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following: I have made numerous attempts on my own to no avail, any assistance is appreciated. Also, template code for this solution is provided below: #include int moveRobots(int *, int *, int, int ); int getNew(int, int); int main() { int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1; // initialize positions of four robots x[0] = 0; y[0]...
Design an application that uses the C# random generator to randomly roll a six face dice...
Design an application that uses the C# random generator to randomly roll a six face dice ( no 1 - no 6) . If the user rolled a 3, the user gets to roll the six face die again. You must use a switch statement to write the result /s of the random dice roll/s to the screen. Hint: You should have nested switches in your program Using: Console App(.NET Framework)
I am playing a game of Dungeon and Dragons with my family. My son’s character must...
I am playing a game of Dungeon and Dragons with my family. My son’s character must roll a critical hit, (19 or 20) on a 20 sided die. Without a critical hit, he cannot do enough damage to the troll. The troll will regenerate and kill me on the next turn. In addition to getting a high roll for hit chance, my son’s character must also get a high roll for damage. His weapon is a great sword and does...
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting)...
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample...
What do I need to implement this code. I need an ADT //--------------------------------------------- // This would...
What do I need to implement this code. I need an ADT //--------------------------------------------- // This would be the Student.h file //--------------------------------------------- #include <iostream> #include <cassert> using namespace std; // each student have a name, an ID (100000000~999999999), and three grades class Student { private: public: Student(); Student(); setName(); setId(); setGrade (); getName(); getId(); getGrade() ; printAll() ; }; //--------------------------------------------- // This would be the Student.cpp file //--------------------------------------------- //====================== YOUR CODE STARTS HERE ====================== Student::Student() //default constructor { } Student::Student(string aName,...
C++, Need to create a code that will calculated the statistics for character input? This is...
C++, Need to create a code that will calculated the statistics for character input? This is the prompt for the code. I truly understand nothing of what it's asking. Ask the user for one character (terminated by a carriage return).Using flow control, classify the character into one of these categories: 1)           vowel 2)           consonant 3)           digit (0-9) 4)           other Output the character input, its numeric decimal value, and the classification. Total up the number of each type of character entered....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT