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();
projectile.GetComponent().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!][1]
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!!!
[1]: http://forum.unity3d.com/threads/34582-Stop-wasting-memory-recycle-your-objects!
↧