Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 samussa201 · Mar 09, 2015 at 08:19 AM · velocityaddforceactivateawakepool

activate and speed in z axis from a pooled inactive object!!

trying to add speed from a cloned GameObject in the z axis from a pool created at start up. any idea how i would go about that? 1. either add speed at activate in first script or 2. attach a script to prefab to acitvate at void Awake() add velocity or force onto the clone?

second question when objects are pooled at start they come out active? how would you have it inactive/disabled at start?

 using UnityEngine;
 using System.Collections;
 
 public class activatPrfab : MonoBehaviour 
 {
     
     public Pool pool;
     public float time = 5;
     
     private Vector3 ringPos;
     
     GameObject[] instPoints;
 
     
     
     // Use this for initialization
     void Start () 
     {
         StartCoroutine(Countdown());
     }
 
     
     void activ()
     {
         GameObject[] instPoints = GameObject.FindGameObjectsWithTag("instant");
         
         int count = Random.Range (0,3);
         
         ringPos = new Vector3(instPoints[count].transform.position.x,instPoints[count].transform.position.y,instPoints[count].transform.position.z);
         
         pool.activate(0, new Vector3(ringPos.x, ringPos.y, ringPos.z), Quaternion.Euler(90, 0, 0));
 
         Debug.Log (count);
         StartCoroutine(Countdown());
         
         //for (int count = 0; count < instPoints.Length; count++)
         //{
         //}
     }
     
     
     IEnumerator Countdown()
     {
         for (float timer = time; timer >= 0; timer -= Time.deltaTime)
             yield return 0;
         activ();
         Debug.Log("This message appears after"+time+"seconds!");
     }
     
 }


pooling script pools at run time script:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Pool : MonoBehaviour {
     
     public GameObject[] objects;
     public int[] No;
     
     public List<GameObject>[] pool;
     
     // Use this for initialization
     void Start () 
     {
         instantiate();
     }
     
     void instantiate()
     {
         GameObject temp;
         pool = new List<GameObject>[objects.Length];
         
         for(int count = 0; count < objects.Length; count++)
         {
             pool[count] = new List<GameObject>();
             
             for(int num = 0; num < No[count]; num++)
             {
                 temp = (GameObject)Instantiate(objects[count]);
                 temp.transform.parent = this.transform;
                 pool[count].Add(temp);
             }
             
         }
     }
     
     public GameObject activate(int id)
     {
         for (int count = 0; count < pool[id].Count; count++) {
             if (!pool [id] [count].activeSelf) {
                 pool [id] [count].SetActive (true);
                 return pool [id] [count];
             }
         }
         return null;
     }
     
     public GameObject activate(int id, Vector3 position, Quaternion rotation)
     {
         for (int count = 0; count < pool[id].Count; count++) 
         {
             if (!pool [id] [count].activeSelf) 
             {
                 pool [id] [count].SetActive (true);
                 pool [id] [count].transform.position = position;
                 pool [id] [count].transform.rotation = rotation;
                 return pool [id] [count];                
             }
         }
         return null;
     }
     
     
 }

Comment
Add comment · Show 1
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 AlwaysSunny · Mar 09, 2015 at 05:29 AM 1
Share

I didn't proofread your code, sorry.

Object pooling isn't terribly complicated. Whether they "come out active" is up to you, but for instance, my pooling script enables objects when they're requested and disables them when they return to the pool.

Any additional action you need to perform that isn't directly related to pooling should be separated from your pooling logic. This allows your pooling script to be "just" a pooling script.

In other words, you want something like:

 GameObject go = Pool.Spawn(myPrefab);
 go.rigidbody.AddForce(whatever);

The wording of your question is confusing, so I'm not sure what exactly you're asking. Please attempt to use proper English grammar and choose your words carefully.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by samussa201 · Mar 09, 2015 at 12:17 PM

tank you so much for taking your time to help out, really appreciated. ended up adding this to my script and made them inactive at start. temp.SetActive(false). and worked great.

 void instantiate()
          {
              GameObject temp;
              pool = new List<GameObject>[objects.Length];
              
              for(int count = 0; count < objects.Length; count++)
              {
                  pool[count] = new List<GameObject>();
                  
                  for(int num = 0; num < No[count]; num++)
                  {
                      temp = (GameObject)Instantiate(objects[count]);
                      temp.transform.parent = this.transform;
                      temp.SetActive(false);
                      pool[count].Add(temp);
                  }
                  
              }



and added this to the game object, just have to make sure the gameObjects facing the right direction.

         void Update() {
             transform.Translate(Vector3.back * Time.deltaTime);
         }





Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rigidbody 2D has velocity but isn't moving after Unity 5 upgrade 2 Answers

Achieving consistent jump height regardless of vertical velocity 2 Answers

,Rotate a gameobject around another while being attracted by its gravity 1 Answer

How to move Character with AddForce 1 Answer

[Solved] How to shoot an object in front of the player? 1 Answer


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