Hi All,
I have some trouble adding some code to my javascript. I am a script noob as you can see
The TouchControl.js script is working perfect when I touch there is a coin instantieating “spawn” at touch position.
Now I want to add the following, when you have touched 5 times it will wait 5 seconds than you can instantiate again for 5 times.
I added a variable “coincounter” and I added “coin counter += 1” in the script so every time I touch it will add 1.
Now I have to check if coincount is equal to 5 then do something like WaitForSeconds and reset the variable “coin counter” to zero again.
I think I have to add another if statement but have no clue where.
I hope i’m right so far and have to put this piece of code to my TouchControl.js somewhere.
Hope someone can help me.
if (coincounter == 5)
{
yield WaitForSeconds (5.0);
coincounter = 0;
}
TouchControl.js
public var coinprefab : Transform;
var coincounter = 0;
var layerMask = 1 << 8;
function Update () {
for (var Touch : Touch in Input.touches) {
if (Touch.phase == TouchPhase.Began) {
var ray = Camera.main.ScreenPointToRay (Touch.position);
var hit: RaycastHit;
if (Physics.Raycast (ray, hit, layerMask)) {
PoolManager.Pools["Money"].Spawn(coinprefab, hit.point, transform.rotation);
scoreScript.score -= 1;
coincounter += 1;
}
}
}
}