Here’s a streamlined tech stack and starter code for your idle game. I’ll focus on Unity, C#, and minimal dependencies to align with the 2-hour/day dev cycle. The code is simplified for clarity but includes core mechanics like tapping, idle progression, and basic upgrades.
Tech Stack Breakdown
Component
Tool/Method
Why?
Engine
Unity 2021+ (2D)
Lightweight, familiar, and supports idle mechanics.
Scripting
C#
Unity’s native language, easy to debug.
Data-Driven Design
ScriptableObjects + CSV
Non-coders can tweak values without code.
UI
Unity Canvas + Prefab Templates
Quick to build; use TextMeshPro for text.
Ads
Unity Ads
Built-in, easy integration.
Save System
PlayerPrefs
Simple for MVP; switch to JSON later if needed.
Localization
JSON Localization
Separate language files (e.g., en.json, pl.json).
Core Scripts
1. MineManager.cs
Handles coal mining, idle calculations, and saves progress.
csharp
using UnityEngine;
using System.Collections;
public class MineManager : MonoBehaviour
{
// Serialized fields for easy tweaking in Unity
[SerializeField] private float _baseCoalPerSecond = 0.1f;
[SerializeField] private TextMeshProUGUI _coalDisplay;
private float _currentCoal = 0f;
private float _lastSaveTime = 0f;
private bool _isIdleActive = true;
void Start()
{
LoadProgress();
StartCoroutine(UpdateIdle());
}
// Calculate idle coal when the game starts/resumes
private void LoadProgress()
{
_currentCoal = PlayerPrefs.GetFloat("CurrentCoal", 0f);
_lastSaveTime = PlayerPrefs.GetFloat("LastSaveTime", Time.realtimeSinceStartup);
}
// Save progress when the app is paused
private void OnApplicationPause(bool paused)
{
if (paused)
{
SaveProgress();
}
}
// Coroutine to update idle coal every second
private IEnumerator UpdateIdle()
{
while (_isIdleActive)
{
float timeSinceLastSave = Time.realtimeSinceStartup - _lastSaveTime;
float idleCoal = timeSinceLastSave * _baseCoalPerSecond;
_currentCoal += idleCoal;
_lastSaveTime = Time.realtimeSinceStartup;
// Update UI
_coalDisplay.text = $"Coal: {_currentCoal:0}";
// Save every 10 seconds to prevent data loss
if (Time.realtimeSinceStartup % 10 < 0.1f)
{
SaveProgress();
}
yield return new WaitForSeconds(1f);
}
}
// Tap-to-mine function (called via UI button)
public void TapMine()
{
_currentCoal += 1f; // Base tap value
_coalDisplay.text = $"Coal: {_currentCoal:0}";
}
// Save to PlayerPrefs
private void SaveProgress()
{
PlayerPrefs.SetFloat("CurrentCoal", _currentCoal);
PlayerPrefs.SetFloat("LastSaveTime", Time.realtimeSinceStartup);
PlayerPrefs.Save();
}
}
2. UpgradeSystem.cs
Manages upgrades and unlocks. Uses CSV data for easy content updates.
csharp
using UnityEngine;
using System.Collections.Generic;
[System.Serializable]
public class UpgradeData
{
public string Name;
public float Cost;
public float CoalPerSecondBonus;
public bool IsPurchased;
}
public class UpgradeSystem : MonoBehaviour
{
[SerializeField] private List<UpgradeData> _upgrades = new List<UpgradeData>();
[SerializeField] private MineManager _mineManager;
void Start()
{
LoadUpgrades();
}
// Load purchased upgrades from PlayerPrefs
private void LoadUpgrades()
{
foreach (var upgrade in _upgrades)
{
upgrade.IsPurchased = PlayerPrefs.GetInt(upgrade.Name + "_Purchased", 0) == 1;
}
}
// Buy an upgrade (called via UI button)
public void BuyUpgrade(int index)
{
var upgrade = _upgrades[index];
if (_mineManager._currentCoal >= upgrade.Cost && !upgrade.IsPurchased)
{
_mineManager._currentCoal -= upgrade.Cost;
upgrade.IsPurchased = true;
PlayerPrefs.SetInt(upgrade.Name + "_Purchased", 1);
PlayerPrefs.Save();
// Apply multiplier
_mineManager._baseCoalPerSecond += upgrade.CoalPerSecondBonus;
}
}
// CSV import method (simplified for MVP)
// Use a CSV parser like `CsvHelper` to read data from a file.
// Example CSV row: "Faster Pickaxe", 100, 0.05, 0
}
3. AdRewards.cs
Integrate Unity Ads for optional monetization.
csharp
using UnityEngine;
using UnityEngine.Advertisements;
public class AdRewards : MonoBehaviour, IUnityAdsListener
{
[SerializeField] private string _androidAdUnitId = "YOUR_ANDROID_AD_UNIT_ID";
[SerializeField] private string _iOSAdUnitId = "YOUR_IOS_AD_UNIT_ID";
[SerializeField] private MineManager _mineManager;
void Start()
{
string adUnitId = (Application.platform == RuntimePlatform.Android)
? _androidAdUnitId
: _iOSAdUnitId;
Advertisement.Initialize(adUnitId, testMode: true);
Advertisement.AddListener(this);
}
// Show a rewarded ad
public void ShowRewardedAd()
{
Advertisement.Show(_androidAdUnitId);
}
// Reward the user when the ad is completed
public void OnUnityAdsDidComplete(string placementId, ShowResult showResult, AdError error = null)
{
if (showResult == ShowResult.Finished)
{
_mineManager._currentCoal += 50f; // Reward 50 coal
}
}
// Other IUnityAdsListener methods (error handling, etc.)
// ... (implement all interface methods for safety)
}
UI Setup (Unity Canvas)
Main Canvas:
A TextMeshPro element for coal display (_coalDisplay).
A Button with an OnClick event linked to MineManager.TapMine().
Upgrade buttons (prefabs) that call UpgradeSystem.BuyUpgrade(index) when clicked.
An "Watch Ad" button linked to AdRewards.ShowRewardedAd().
Data-Driven UI:
Use a Prefab for upgrades (e.g., UpgradeButton).
Instantiate buttons dynamically from _upgrades list in UpgradeSystem:
csharp
// In UpgradeSystem.cs
public Transform _upgradeContainer;
void Start() {
foreach (var upgrade in _upgrades) {
var btn = Instantiate(upgradePrefab, _upgradeContainer);
btn.GetComponentInChildren<TextMeshProUGUI>().text = $"{upgrade.Name}\nCost: {upgrade.Cost}";
btn.GetComponent<Button>().onClick.AddListener(() => BuyUpgrade(index));
}
}
CSV Data Example
Save creature/upgrades in a CSV for easy content updates:
csv
// Creatures.csv
Name,Multiplier,BuffType
Leszy,1.2,"Grants +10% coal per second"
Rusalka,1.5,"Reduces ad cooldown by 20%"
Strzyga,2.0,"Double tap reward on weekends"
Key Considerations
Offline Calculation:
The UpdateIdle() coroutine uses Time.realtimeSinceStartup for accurate offline time tracking.
Save progress on pause to prevent data loss.
Localization:
Use JSON files for translations (e.g., Localization/en.json):
json
{
"TapToMine": "Kliknij, aby wydobyć węgiel",
"Upgrades": "Ulepszenia"
}
Scalability:
Add new features (e.g., creature collection) by extending ScriptableObjects or CSV data.
Use ScriptableObjects for creature buffs (e.g., CreatureBuff.cs).
Next Steps
Art Integration:
Import the 500×500 creature silhouettes as sprites.
Use a Sprite Atlas for efficient rendering.
Polish:
Add particle effects for tapping (e.g., a coal particle system).
Implement the "time expedition" minigame (e.g., a simple timer-based event).
Testing:
Use Unity’s Test Build for Android/iOS.
Validate offline/idle calculations across devices.
This framework should take ~20 hours of coding time (10 days at 2 hours/day). Let me know if you need help with specific parts! 🛠️