- Home /
How do I pause and unpause multi gameobjects in the scene for a five seconds
Right now the code I have disable game object . What I ment to do is pause and unpause game object .When the scene plays I don't see the game object because the whole body is disable . I don't want that . I want to be able to see the gameobject and not be able to move the gameobject . I also gonna have music . I need that pause to too. I just want to be able to pause and unpause the player and the enemy ai's and weapons. Anything that is gonna move I want it to be pause and unpause for a couple of seconds . Here is my code :
using UnityEngine;
using System.Collections;
public class yu : MonoBehaviour {
public float disableTime = 5f;
private float t = 0f;
// Use this for initialization
void Start () {
StartCoroutine(DisableGameObjects());
}
private IEnumerator DisableGameObjects() {
Transform[] transforms = GetComponents<Transform>();
foreach(Transform tr in transforms) {
tr.gameObject.SetActive(false);
}
yield return new WaitForSeconds(disableTime);
foreach(Transform tr in transforms) {
tr.gameObject.SetActive(false);
}
}
}
Answer by flaviusxvii · Aug 31, 2016 at 07:56 PM
This should be helpful https://www.sitepoint.com/adding-pause-main-menu-and-game-over-screens-in-unity/
Glad it helped. I googled "unity3d pause game" and was the 6th or 7th result on the page. Search first and then ask later.
Your answer
Follow this Question
Related Questions
Is a global static boolean a good implementation for pausing my game? 2 Answers
How do i change my background for android gaming 1 Answer
Script c+.How i throw player to any area.? 1 Answer
Problem with Pause and WaitForSeconds 2 Answers
Pause game when user pulls down the notification panel 0 Answers