- Home /
How do I pause and unpause only some GameObjects at a time
Hey this is my first game I'm designing. I'm trying have to two or three "worlds" in a level. When I hit the spacebar from my initial character, I want to be able to toggle through the list of characters (one on each world) and hit spacebar again and only unpause that "world" and character that the camera is targeted on.
I want to do this accurate so when i play with one character and if i pause mid-jump, I can change to someone else, play their part, then come back and still be in the air with the initial character.
Answer by Jesse Anders · Sep 02, 2010 at 05:49 AM
What I would try is enabling and disabling the appropriate components as appropriate. You'll want to enable/disable your own scripts that do any movement or other updating, and also any particle systems and rigid bodies. I don't believe the rigidbody component can be disabled per se, but setting a rigid body to 'kinematic' (if it's not kinematic already) should have the same effect.
The second part of the problem is identifying all of the appropriate game objects based on which world you want to pause/unpause. There's more than one way this problem can be solved, but possible solutions would be to query for game objects based on layers or tags. By combining this with GetObjectsOfType(), you can acquire all of the particle systems, rigid bodies, and other component types that you're interested in, and then check the tags/layers/other metadata to see which should be enabled and which disabled. (I've read that GetObjectsOfType() can be slow in some cases. I don't know whether it would be a problem in this scenario, but I'd go ahead and try it and see how it performs.)
One trick I've used for pausing is to derive all of the monobehaviours that I want to be pausable from a 'Pausable' base class. The 'Pausable' class simply derives from Monobehaviour, and does nothing more; it simply serves as a 'tag' of sorts that allows GetObjectsOfType() to find these components easily. (This is in C#; I'm not sure if/how this can be done in UnityScript or Boo, although I imagine something similar would be possible.)
Thanks for answering man... So for the script, would it be like GetObjectsOfType(World1)... meaning everything i've tagged world1 in world 1...
Read up on FindWithTag (http://unity3d.com/support/documentation/ScriptReference/GameObject.FindWithTag.html) and FindObjectsOfType (http://unity3d.com/support/documentation/ScriptReference/Object.FindObjectsOfType.html). There are examples on both pages.
Thanks you guys, I'll try this and see what I run into.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072444im_/https://answers.unity.com/themes/thub/images/avi.jpg)