mirror of
https://github.com/smyalygames/monopoly.git
synced 2025-12-19 19:19:44 +01:00
Added a dice roller
This commit is contained in:
38
Assets/Scripts/RollDice.cs
Normal file
38
Assets/Scripts/RollDice.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RollDice.cs.meta
Normal file
11
Assets/Scripts/RollDice.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 674a12b58c717a04f81c76e5abb4ac70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
25
Assets/Scripts/WebTest.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/WebTest.cs.meta
Normal file
11
Assets/Scripts/WebTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71e89e63889ac1c4589d15554266b266
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user