Hello there,
I’ve read several threads about delaying a shot in unity. The answer is almost the same.
Here is my Code:
private void Update()
{
if (Input.GetButton("Fire1") && Time.time > FireRateTimer)
{
Debug.Log(FireRateTimer);
GameObject ProjectileVar = (GameObject)Instantiate(Projectile, projectileSpawn.position, Quaternion.identity);
Vector2 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 myPos = new Vector2(transform.position.x, transform.position.y + 1);
Vector2 direction = target - myPos;
direction.Normalize();
ProjectileVar.GetComponent<Rigidbody2D>().AddForce(direction * 4000);
FireRateTimer = Time.time + FireRate;
SoundTurret.PlayOneShot(ShootSound);
}
}
But no matter what number is given to FireRate it still shoots like every 1 seconds. I’ve checked the values with debug command and it’s mostly a second.
I don’t have any clue why this isn’t working because the Time.time thing should be the solution for that, following the threads with that topic.