init
This commit is contained in:
26
Assets/Scripts/Chip.cs
Normal file
26
Assets/Scripts/Chip.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Chip : MonoBehaviour
|
||||
{
|
||||
public float value;
|
||||
|
||||
void Awake(){
|
||||
RouletteManager.OnMoneyAvailablChanged.AddListener(OnMoneyChanged);
|
||||
}
|
||||
|
||||
|
||||
void OnMoneyChanged(float newMoney){
|
||||
gameObject.SetActive(newMoney >= value);
|
||||
}
|
||||
|
||||
|
||||
void OnValidate(){
|
||||
if(value == 0){
|
||||
try{
|
||||
value = float.Parse(gameObject.name.Replace("chip_",""));
|
||||
}catch{}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Chip.cs.meta
Normal file
11
Assets/Scripts/Chip.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 660d118b5be3a004f9ca763fae797afd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Scripts/RouletteManager.cs
Normal file
22
Assets/Scripts/RouletteManager.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class RouletteManager : MonoBehaviour
|
||||
{
|
||||
private static float moneyAvailable = 1000;
|
||||
public static float MoneyAvailable {get{ return moneyAvailable;} set{OnMoneyAvailablChanged.Invoke(value); moneyAvailable = value;}}
|
||||
public static UnityEvent<float> OnMoneyAvailablChanged = new UnityEvent<float>();
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
Spinner.OnSpinStopped.AddListener(OnSpinStopped);
|
||||
}
|
||||
|
||||
void OnSpinStopped(int landedValue){
|
||||
MoneyAvailable -= 100;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/RouletteManager.cs.meta
Normal file
11
Assets/Scripts/RouletteManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ba6b35476b1f8840af7ddfa1cda9d2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
86
Assets/Scripts/Spinner.cs
Normal file
86
Assets/Scripts/Spinner.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class Spinner : MonoBehaviour
|
||||
{
|
||||
|
||||
public static int LandedNumber{get; private set;}
|
||||
public static UnityEvent<int> OnSpinStopped = new UnityEvent<int>();
|
||||
public Transform wheel;
|
||||
public Vector3 rotationAxis;
|
||||
public float CurrentRotation { get{ return (wheel.rotation * rotationAxis).magnitude;}}
|
||||
[Tooltip("Initial Spin force")]
|
||||
public float SpinForce = 10;
|
||||
[Tooltip("How smooth the speed goes up")]
|
||||
public float SpinSmoothness = 1f;
|
||||
[Tooltip("How smooth the speed goes down")]
|
||||
public float Friction = 0.005f;
|
||||
[Tooltip("When should the wheel stop")]
|
||||
public float StopSpeed =0.01f;
|
||||
public int offset = -4;
|
||||
public int CurNumber;
|
||||
public float CurrentSpeed {get; private set;}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Debug.Log(RouletteNumbers.Length);
|
||||
}
|
||||
bool pushing = false;
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
HandleFriction();
|
||||
wheel.Rotate(rotationAxis * CurrentSpeed);
|
||||
CurNumber = GetLandedNumber();
|
||||
}
|
||||
|
||||
void HandleFriction(){
|
||||
if(pushing){return;}
|
||||
if(CurrentSpeed > 0){
|
||||
if(CurrentSpeed < StopSpeed){
|
||||
CurrentSpeed=0;
|
||||
m_onSpinStopped();
|
||||
}else{
|
||||
CurrentSpeed -= Friction;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Spin(){
|
||||
StartCoroutine(spin());
|
||||
}
|
||||
|
||||
IEnumerator spin(){
|
||||
pushing=true;
|
||||
while(CurrentSpeed < SpinForce){
|
||||
CurrentSpeed += SpinSmoothness;
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
pushing = false;
|
||||
}
|
||||
|
||||
public int[] RouletteNumbers = {0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26};
|
||||
|
||||
private void m_onSpinStopped(){
|
||||
|
||||
LandedNumber = GetLandedNumber();
|
||||
Debug.Log($"Landed on {LandedNumber}");
|
||||
|
||||
|
||||
OnSpinStopped.Invoke(LandedNumber);
|
||||
}
|
||||
|
||||
int GetLandedNumber(){
|
||||
float fraction = ((wheel.eulerAngles.z) / 360f) * (float)RouletteNumbers.Length;
|
||||
int index= Mathf.RoundToInt(fraction) + offset;
|
||||
if(index < 0){
|
||||
index = RouletteNumbers.Length + index - 1;
|
||||
}else if(index >= RouletteNumbers.Length){
|
||||
index = index - RouletteNumbers.Length;
|
||||
}
|
||||
int m_LandedNumber = RouletteNumbers[index];
|
||||
|
||||
return m_LandedNumber;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Spinner.cs.meta
Normal file
11
Assets/Scripts/Spinner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb5ba52475e9a61408be1b1e4e03191c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user