Идея этой игры заключается в том, чтобы на компьютере была установлена базовая графическая карта. Когда игрок нажимает на ПК, он отображает панель, на которой отображается некоторая информация о мощности майнинга этой графической карты, а также кнопка «Старт» для начала майнинга и «Криптотекст», который обновляется. Игрок может купить больше установок в StorePanel. Когда установка отображается на сцене, игрок также может коснуться ее, чтобы начать майнинг, но с другой мощностью майнинга, и ему необходимо обновить «CryptoText», как и накопление, но вы можете увидеть это в видео, как это работает, в том же «Криптотексте», но не накапливается. Референсы — это наборы, а риги — префабы в папке «Активы».
Если кто-то может мне помочь, я буду очень признателен!
Код: Выделить всё
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class UIController : MonoBehaviour
{
public GameObject infoPanel;
public CryptoMining cryptoMining;
public Button mineButton;
public Text moneyText;
public Text cryptoText;
private Animator infoPanelAnimator;
public ElectricityManager electricityManager; // Referință la scriptul ElectricityManager
private float playerMoney = 123250f;
private float cryptoAmount = 0f;
void Start()
{
infoPanelAnimator = infoPanel.GetComponent();
UpdateMoneyText();
UpdateCryptoText();
}
public void OnMineButtonClicked()
{
cryptoMining.StartMining();
mineButton.interactable = false;
}
public void OnCloseButtonClicked()
{
infoPanelAnimator.SetTrigger("Hide");
}
public void ShowInfoPanel()
{
infoPanel.transform.localScale = Vector3.zero;
infoPanelAnimator.SetTrigger("Show");
mineButton.interactable = true;
}
private void UpdateMoneyText()
{
if (moneyText != null)
{
moneyText.text = "Money: " + playerMoney.ToString("F2");
}
else
{
Debug.LogError("moneyText reference is not set in the Inspector.");
}
}
private void UpdateCryptoText()
{
if (cryptoText != null)
{
cryptoText.text = "Crypto: " + cryptoAmount.ToString("F6");
}
else
{
Debug.LogError("cryptoText reference is not set in the Inspector.");
}
}
public void AddCrypto(float amount)
{
cryptoAmount += amount;
UpdateCryptoText();
}
public void AddMoney(float amount)
{
playerMoney += amount;
UpdateMoneyText();
}
public void SpendMoney(float amount)
{
if (playerMoney >= amount)
{
playerMoney -= amount;
UpdateMoneyText();
}
else
{
Debug.LogError("Not enough money to complete the transaction.");
}
}
public void SpendCrypto(float amount)
{
if (cryptoAmount >= amount)
{
cryptoAmount -= amount;
UpdateCryptoText();
}
else
{
Debug.LogError("Not enough crypto to complete the transaction.");
}
}
public float GetPlayerMoney()
{
return playerMoney;
}
public float GetCryptoAmount()
{
return cryptoAmount;
}
}
Код: Выделить всё
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class MiningRig : MonoBehaviour
{
public float miningPower; // Puterea de minare specifică rig-ului
public float miningInterval; // Intervalul de timp pentru minare
public float miningRate = 0.0005f;
public UIController uiController;
private MiningManager miningManager;
public CryptoMining cryptoMining;
private bool isMining = false;
void Start()
{
if (miningManager == null)
{
miningManager = FindObjectOfType();
if(miningManager == null)
{
Debug.LogError("mining manager not found in");
}
}
// Ne asigurăm că obiectul are un BoxCollider
if (GetComponent() == null)
{
gameObject.AddComponent();
}
// Încercăm să găsim UIController dacă nu este setat
if (uiController == null)
{
uiController = FindObjectOfType();
if (uiController == null)
{
Debug.LogError("UIController not found in the scene. Please assign it in the inspector.");
}
}
}
public void SetMiningPower(float power)
{
miningPower = power;
}
public void SetMiningInterval(float interval)
{
miningInterval = interval;
}
void OnMouseDown()
{
if (!isMining)
{
StartMining();
}
}
void StartMining()
{
if (!isMining)
{
isMining = true;
InvokeRepeating("MineCrypto", 0f, 1f);
Debug.Log("Mining rig started");
}
}
void MineCrypto()
{
if (MiningManager.Instance == null)
{
Debug.LogError("MiningManager instance not found. Please ensure it exists in the scene.");
return;
}
if (uiController == null)
{
Debug.LogError("UIController reference is missing. Please assign it in the inspector or ensure it exists in the scene.");
return;
}
float minedAmount = miningRate * MiningManager.Instance.GetGlobalMiningRateFactor();
uiController.AddCrypto(minedAmount);
Debug.Log("Mining rig mined: " + minedAmount);
}
public void StopMining()
{
isMining = false;
}
}
Код: Выделить всё
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class CryptoMining : MonoBehaviour
{
public Text cryptoText;
public float miningInterval = 3f;
public float miningRate = 0.134134f;
public float cryptoValue = 0.01f;
public UIController uiController;
private float cryptoAmount = 0f;
private bool isMining = false;
public float miningPower = 0.1f;
private float originalMiningPower;
private float globalMiningRateFactor = 1f;
public float baseMiningRate = 0.001753f;
void Start()
{
originalMiningPower = miningPower;
UpdateCryptoText();
}
public void StartMining()
{
if (!isMining)
{
isMining = true;
InvokeRepeating("MineCrypto", 0f, miningInterval);
}
}
void MineCrypto()
{
cryptoAmount += miningRate * miningPower;
UpdateCryptoText();
if (uiController != null)
{
uiController.AddMoney(miningRate * miningPower * cryptoValue);
}
else
{
Debug.LogError("UIController reference is not set in the CryptoMining script.");
}
}
public void SetMiningEfficiency(float efficiency)
{
globalMiningRateFactor = efficiency;
}
public void ReduceMiningEfficiency(float factor)
{
miningPower = originalMiningPower * factor;
Debug.Log($"Mining efficiency reduced. New mining power: {miningPower}");
}
// Adăugat metoda GetBaseMiningRate pentru a obține rata de minare de bază
public float GetBaseMiningRate()
{
return baseMiningRate;
}
public float GetGlobalMiningRateFactor()
{
return globalMiningRateFactor;
}
public void ResetMiningEfficiency()
{
miningPower = originalMiningPower;
Debug.Log($"Mining efficiency reset. Mining power: {miningPower}");
}
private void UpdateCryptoText()
{
if (cryptoText != null)
{
cryptoText.text = $"Crypto: {cryptoAmount:F6}";
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... game-unity