I cannot find any problem with my bullet script. I add this script to my gun but the bullet won’t spawn.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour {
//Identify components
public Rigidbody2D rb;
public Transform tf;
//Identify game objects
public GameObject bullet;
public bool isShooting = false;
public float bulletShootingSpeed = 1.0f;
void Start() { }
void Update() {
canShoot();
}
IEnumerator BulletShootingSpeed()
{
spawnBullet();
yield return new WaitForSeconds(bulletShootingSpeed);
}
void spawnBullet()
{
while (isShooting == true)
{
Instantiate(bullet, tf.position, Quaternion.Euler(new Vector2(0, 0)));
}
}
void canShoot()
{
while (Input.GetKey(KeyCode.F))
{
isShooting = true;
}
}
}