Added a dice roller

This commit is contained in:
Anthony Berg
2020-06-22 19:30:16 +01:00
parent c37206aaa9
commit 83624f3bf4
7 changed files with 633 additions and 13 deletions

View File

@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RollDice : MonoBehaviour
{
System.Random random = new System.Random();
private int current;
private Waypoints waypoints;
public Button m_RollDice;
void Awake()
{
waypoints = GameObject.FindObjectOfType<Waypoints>();
}
// Start is called before the first frame update
void Start()
{
m_RollDice.onClick.AddListener(TaskOnClick);
}
// Update is called once per frame
void Update()
{
}
void TaskOnClick() {
current = random.Next(1, 7) + random.Next(1, 7);
Debug.Log("Rolled: " + current);
waypoints.UpdateRoll(current);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 674a12b58c717a04f81c76e5abb4ac70
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,27 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Waypoints : MonoBehaviour
{
public int roll;
int position = 0;
public GameObject[] waypoints;
int current = 0;
float rotSpeed;
public float speed;
float WPradius = 0;
double WPradius = 0.001;
// Update is called once per frame
public void UpdateRoll(int passedRoll)
{
roll += passedRoll;
if (roll >= 40)
{
roll -= 40;
}
}
void Update()
{
if(Vector3.Distance(waypoints[current].transform.position, transform.position) < WPradius)
if ((Vector3.Distance(waypoints[position].transform.position, transform.position) < WPradius) && position != roll)
{
current++;
if (current >= waypoints.Length)
//Debug.Log(waypoints[current]);
position++;
if (position >= waypoints.Length)
{
current = 0;
position = 0;
}
}
transform.position = Vector3.MoveTowards(transform.position, waypoints[current].transform.position, Time.deltaTime * speed);
transform.position = Vector3.MoveTowards(transform.position, waypoints[position].transform.position, Time.deltaTime * speed);
}
}

25
Assets/Scripts/WebTest.cs Normal file
View File

@@ -0,0 +1,25 @@
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class WebTest : MonoBehaviour {
void Start() {
StartCoroutine(GetText());
}
IEnumerator GetText() {
UnityWebRequest www = UnityWebRequest.Get("https://monopoly.smyalygames.com/test.php");
yield return www.SendWebRequest();
if(www.isNetworkError || www.isHttpError) {
Debug.Log(www.error);
}
else {
// Show results as text
Debug.Log(www.downloadHandler.text);
// Or retrieve results as binary data
byte[] results = www.downloadHandler.data;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71e89e63889ac1c4589d15554266b266
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: