Question by
Tropicaliste · Aug 04, 2016 at 03:03 PM ·
javascript
Tree Chopping/Harvesting cooldown
So i made a tree "harvesting" script and i want to have a cooldown for it. I dont want the player to be able to spam the button and get Wood and Exp from it. I'd like to have an cooldown system so i can Harvest and wait for 10 seconds and harvest again after the 10second cooldown. But i cannot find anything like this anywhere so im asking help here. Sorry for bad grammar, english is not my native language.
Code =
#pragma strict
var TreeHarvest : boolean = false;
var menuSkin : GUISkin;
public var Player : GameObject;
private var InventoryScript : Inventory;
private var ExpScript : ExpSystem;
var canHarvest : boolean = false;
function Start () {
}
function Update ()
{
}
function HarvestTree ()
{
InventoryScript = Player.GetComponent(Inventory);
InventoryScript.wood += 1;
ExpScript = Player.GetComponent(ExpSystem);
ExpScript.Exp += 1;
}
function OnTriggerEnter (other : Collider)
{
if(other.tag == "Tree") {
TreeHarvest = true;
}
}
function OnTriggerExit (other : Collider)
{
if(other.tag == "Tree"){
TreeHarvest = false;
}
}
function OnGUI ()
{
if(TreeHarvest == true)
{
GUI.skin = menuSkin;
GUI.BeginGroup(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300));
GUI.Box(Rect(0, 0, 300, 300), "Tree Harvesting");
if(GUI.Button(Rect(60, 50, 20, 20), "Harvest Tree" ))
{
if(canHarvest == true) {
HarvestTree();
}
}
}
}
Comment