So I’ve been scratching my head on this for about 2 days. What’s suppose to happen is a resource is spawned, you click on it, and it is suppose to add 25 to your resource count, then destroy itself. (like the sun power in plants versus zombies)
And more or less this is happening as it should. Except that odd time, it will add 50 or even 100 to the resource count.
#pragma strict
var resourceValue: int = 25;
var Countdown: int = 5;
var visible: float = 0.50;
var invisible: float = 0.50;
var blinkFor: float = 5.0;
var startState: boolean = true;
var explosion: GameObject;
function Start ()
{
animation.Play ();
transform.position.z = -5;
renderer.enabled = startState;
yield WaitForSeconds(Countdown);
var whenAreWeDone = Time.time + blinkFor;
while (Time.time < whenAreWeDone)
{
if ( startState )
{
renderer.enabled = false;
yield WaitForSeconds(invisible);
renderer.enabled = true;
yield WaitForSeconds(visible);
}
else
{
renderer.enabled = true;
yield WaitForSeconds(visible);
renderer.enabled = false;
yield WaitForSeconds(invisible);
}
}
renderer.enabled = true;
Destroy ( gameObject );
}
function Update ()
{
var hit :RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if ( Physics.Raycast ( ray, hit, 30 ))
{
if ( hit.collider.gameObject.tag == "resource" && Input.GetMouseButtonDown (0))
{
var getResources = GameObject.Find("_LevelMaster");
getResources.GetComponent(LevelMaster).resourceCount += resourceValue;
getResources.GetComponent(LevelMaster).UpdateHUD ();
Instantiate ( explosion, hit.collider.gameObject.transform.position, Quaternion.identity );
Destroy (hit.collider.gameObject);
}
}
}
Any help you can offer would be greatly appreciated!
Thanks