Dice
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Arrow : MonoBehaviour
|
||||
{
|
||||
private bool clicked = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Deactivate();
|
||||
}
|
||||
|
||||
public bool IsClicked()
|
||||
{
|
||||
return clicked;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
clicked = false;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnMouseDown()
|
||||
{
|
||||
clicked = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ea731c79e81374aa55c0f0bf8183c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Dice : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text[] numbers;
|
||||
[SerializeField] private Rigidbody rb;
|
||||
private bool started;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rb.useGravity = false;
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void StartRandom()
|
||||
{
|
||||
if (!started)
|
||||
{
|
||||
rb.useGravity = false;
|
||||
gameObject.SetActive(true);
|
||||
started = true;
|
||||
InvokeRepeating("RandomNumbers", 0f, 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopRandom(int dec)
|
||||
{
|
||||
started = false;
|
||||
CancelInvoke("RandomNumbers");
|
||||
|
||||
rb.useGravity = true;
|
||||
rb.angularVelocity = new Vector3(Random.Range(5, 10), Random.Range(5, 10), Random.Range(5, 10));
|
||||
|
||||
foreach (TMP_Text t in numbers)
|
||||
{
|
||||
t.text = dec.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void RandomNumbers()
|
||||
{
|
||||
int random = Random.Range(1, 7);
|
||||
|
||||
rb.angularVelocity = new Vector3(Random.Range(5, 10), Random.Range(5, 10), Random.Range(5, 10));
|
||||
foreach (TMP_Text t in numbers)
|
||||
{
|
||||
t.text = random.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70821f71a92e74a458d3c9851df96456
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user