Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by drodrii · Mar 07, 2014 at 04:20 PM · gameobjectpoolprotection

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!!!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image drodrii · Mar 07, 2014 at 05:27 PM 0
Share

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!

avatar image Dblfstr · Mar 07, 2014 at 05:48 PM 0
Share

haha no problem

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Efficiency of Game Loops 2 Answers

Using script's method from all of the gameobjects that has that script 2 Answers

How to create 3D game object in specified pixel size? 2 Answers

Unity3D Pressure Plate request. 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges