I am making a bullethell for a friend for his birthday. I’m doing pooling for bullet recycling but when I try it it gives me this error “The variable bulletPosition of Loli has not been assigned”.
This is the code I made to the character
public class Loli : MonoBehaviour
{
private float horizontal, vertical;
private float speed = 8f;
public GameObject bullet;
[SerializeField] private Rigidbody2D rb;
[SerializeField] private GameObject bulletPrefab;
[SerializeField] private Transform bulletPosition;
private void Update()
{
transform.Translate(
Input.GetAxis("Horizontal") * 5f * Time.deltaTime,
Input.GetAxis("Vertical") * 5f * Time.deltaTime, 0f);
if (Input.GetButtonDown("Fire1"))
{
Fire();
}
}
private void Fire()
{
//Instantiate(bulletPrefab, bulletPosition.position, Quaternion.identity);
GameObject bullet = ObjectPool.instance.GetPooledObject();
if (bullet != null)
{
bullet.transform.position = bulletPosition.position;
bullet.SetActive(true);
}
}
}