You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.6 KiB
102 lines
2.6 KiB
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
/// <summary> |
|
/// The Game Controller manages the general play of the game. It handles tracking |
|
/// and management of the player's pool of resources and the automatic increase of |
|
/// the pool over time. |
|
/// |
|
/// Attach this class to an empty game object in your Hierarchy panel. |
|
/// |
|
/// This idle game is a clone of the Cookie Clicker application at http://orteil.dashnet.org/cookieclicker/ |
|
/// </summary> |
|
public class GameController : MonoBehaviour { |
|
|
|
#region Properties |
|
/// <summary> |
|
/// How much is in the player's pool |
|
/// </summary> |
|
private float _pool; |
|
public float Pool |
|
{ |
|
get |
|
{ |
|
return _pool; |
|
} |
|
|
|
set |
|
{ |
|
_pool = value; |
|
poolText.text = PoolTextPrefix + _pool.ToString("0.00"); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// How much the pool is automatically incremented per second |
|
/// </summary> |
|
private float _increasePerSecond; |
|
public float IncreasePerSecond |
|
{ |
|
get |
|
{ |
|
return _increasePerSecond; |
|
} |
|
|
|
set |
|
{ |
|
_increasePerSecond = value; |
|
rateText.text = "per second: " + _increasePerSecond.ToString("0.0"); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// The pool text prefix. |
|
/// </summary> |
|
public string PoolTextPrefix; |
|
|
|
/// <summary> |
|
/// Represents the click power of each button click. Each button click |
|
/// will add this much to the player's pool. |
|
/// </summary> |
|
[Tooltip("How many reasources the player will make when they hit the button.")] |
|
public float powerPerClick = 1; |
|
|
|
// In the Hierarchy panel, select the empty game object that holds this controller, |
|
// drag and drop each game object onto these properties in the inspector panel. |
|
[Header("Object References")] |
|
public Text poolText; |
|
public Text rateText; |
|
#endregion |
|
|
|
#region Methods |
|
/**** |
|
* Button click event handler for the main game button. Select the game button in |
|
* the hierarchy. In the inspector find the On Click() section and click the + button |
|
* drag the game controller from the hierarchy onto the object reference in the click |
|
* section. Then select GameController.ClickedButton from the method drop down. |
|
*****/ |
|
public void ClickedButton() |
|
{ |
|
// Each button click will increment the pool by the click power value. |
|
Pool += powerPerClick; |
|
} |
|
#endregion |
|
|
|
#region MonoBehavior |
|
// Use this for initialization |
|
void Start() |
|
{ |
|
Pool = 0; |
|
IncreasePerSecond = 0; |
|
} |
|
|
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
// Each second the game is running, increment the pool by the Increase per second |
|
// value. Increase per second is increased by purchasing upgrades from the store. |
|
Pool += IncreasePerSecond * Time.deltaTime; |
|
} |
|
#endregion |
|
|
|
}
|
|
|