// Update is called once per frame void Update() { timeStamp += Time.deltaTime; if (fireRate <= timeStamp) { enemy = GetClosestEnemy(); distEnemy = Vector2.Distance(transform.position, enemy.transform.position); if (distEnemy <= range) { target = enemy.transform.position; direction = enemy.transform.position - transform.position; bulletO = Instantiate(Bullet); bulletO.transform.SetParent(transform, false); bulletScript = bulletO.GetComponent <BulletScript>(); bulletScript.damage = damage; bulletScript.BulletLand(target, 100); timeStamp = 0; } } }