I’m trying to add an effect to my main menu that causes 3 bulletholes to appear on the menu as the player clicks play, however, after getting all the bullethole decals set up, code written and art aspects done, I seem to have done something stupid with my deltatime timers. I’m sure that i’ve done the timer right, although every timer on the script fails to tick down even after its conditions are completed.
I’m not really sure whats wrong with this, so here’s the code. See if you guys can find whatever is wrong with this. And yes, i did apply the script to an object. Don’t worry about that. Either way, i’m stumped. I feel like i’m missing something very basic.
#pragma strict
public var bulletholeTimer : float = 2.0f;
public var timeBetweenBullets : float = 1.1f;
public var soundTimer : float = 1.0f;
public var bulletHole : Rigidbody;
public var spawnPoint1 : Transform;
public var spawnPoint2 : Transform;
public var spawnPoint3 : Transform;
public var gunShot : AudioSource;
var testcount : float = 10.0f;
function start ()
{
}
function update ()
{
testcount -= Time.deltaTime;
bulletholeTimer -= Time.deltaTime;
if(bulletholeTimer <= 0.0f)
{
bulletHole = Instantiate(bulletHole, spawnPoint1.position, spawnPoint1.rotation);
gunShot.enabled = true;
soundTimer -= Time.deltaTime;
timeBetweenBullets -= Time.deltaTime;
}
if( (bulletholeTimer <= 0.0f) ||
(Input.GetKeyDown(KeyCode.A) ))
{
bulletHole = Instantiate(bulletHole, spawnPoint2.position, spawnPoint2.rotation);
gunShot.enabled = true;
}
if(timeBetweenBullets <= -1.1f)
{
bulletHole = Instantiate(bulletHole, spawnPoint3.position, spawnPoint3.rotation);
gunShot.enabled = true;
}
}