-1

I am following a tutorial on how to make a gun to shoot a bullet, but I am getting this error:

"The name 'ObjectPoolingManager' does not exist in the current context"

I am following the tutorial exactly as is, and I don't know why this happens.

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PL : MonoBehaviour {
    public GameObject bulletPrefab;

    public Camera playerCamera;

    // Update is called once per frame
    void Update() {
        if (Input.GetMouseButtonDown(0)) {
            GameObject bulletObject = ObjectPoolingManager.Instance.GetBullet(true);
            bulletObject.transform.position = playerCamera.transform.position + playerCamera.transform.forward;
            bulletObject.transform.forward = playerCamera.transform.forward;
        }
    }
}
Rodrigo Rodrigues
  • 7,545
  • 1
  • 24
  • 36
Arya Akhavein
  • 343
  • 1
  • 7
  • Well, have you implemented such a type? Because it's not Unity built-in ;) – derHugo May 14 '21 at 20:37
  • 2
    Seems to be one of their objects, according to Google. Tutorial probably missing something you need. – Nikki9696 May 14 '21 at 20:39
  • @Nikki9696 that is most likely the issue – Arya Akhavein May 14 '21 at 20:43
  • 1
    @Nikki9696 I believe you are correct, i read the entire tutorial, i believe the `ObjectPoolingManager` class was excluded from the tutorial. @Arya Akhavein [Heres a tutorial](https://learn.unity.com/tutorial/introduction-to-object-pooling#5ff8d015edbc2a002063971b) to make your own `ObjectPoolingManager` since they didn't included it with the project. – DekuDesu May 14 '21 at 22:22

2 Answers2

1

I wouldn't worry too much about object pooling until you're comfortable with the basics of Unity and C#. It is an optimization pattern. I would just GameObject.Instantiate(yourBulletPrefab) and GameObject.Destroy(yourBulletGameobject) instead until performance becomes an issue.

Charly
  • 450
  • 2
  • 13
0

Unity doesn't have built-in object pooling. You have to create yourself. Tutorial which you followed forgot to add it.