- Home /
 
Proper way to Pool Object - Can't acces due to protection level
Hello everyone, I wanted to corroborate the way Im creating a "bullet" pool.
So, I've attached a script to a static object. Where it gets mouseInput from the user. As soon as its clicked it creates an object.
Here's part of the Script
 public GameObject object2Spawn;
 public bulletActions projectile;
 
 void Update () 
     {
 
         if(Input.GetMouseButtonDown(1))
         {
             //Some variables I've deleted to make this shorter.(They're not the problem)
 
          projectile = ObjectPoolManager.CreatePooled( object2Spawn, transform.position, player.transform.rotation ).GetComponent<bulletActions>();
             projectile.GetComponent<bulletActions>().moveTowards(userInputPosition);
 
         }
     }
 
               And here's bulletActions script
 public class bulletActions : MonoBehaviour {
 
     float moveSpeed = 0.5f;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnTriggerEnter (Collider other) {
 
         Debug.Log ("OnTrigger");
         Debug.Log (collider.gameObject.name);
         Destroy(this.gameObject);
         Destroy (other.gameObject);
 
         }
 
 
     void moveTowards (Vector3 direction) 
     {
 
         transform.position = Vector3.Lerp(transform.position, direction, moveSpeed);
     }
 
 }
 
               I think its a fairly simple script, added a bounding box that tells that if it collides with something else, destroy it.
Now. I've got 2 issues. I got a script from the forums that instantiates and manages pooled objects. From here:
1-http://forum.unity3d.com/threads/34582-Stop-wasting-memory-recycle-your-objects! And I don't know if Im creating the pooled object correctly.
2-Im trying to access 'bulletActions' method called MoveTowards like this "projectile.GetComponent().moveTowards(userInputPosition);" but Im getting this error bulletActions.MoveTowards(Unity.Engine Vector3)' is inaccessible due to its protection level.
Am I properly casting the first issue && how do I solve my second issue!? help please!!!
Answer by Dblfstr · Mar 07, 2014 at 04:25 PM
This is the object pool I have used: http://forum.unity3d.com/threads/76851-Simple-Reusable-Object-Pool-Help-limit-your-instantiations!
Also, your moveTowards() needs to be
 public void moveTowards(){}
 
               If you want access to it.
I want to kill myself hahaha! I didn't realize I didn't add public...Thanks for your time and the link will surely check it out!
Your answer