I can't get my gameobject to pause on its own / How do I code the gameobject to pause and unpause by itself in c# on unity3d
I am having trouble figuring out how to pause and unpause the gameobject . I need the gameobject to pause for a eight seconds or longer . Here is what I got for code :
using UnityEngine;
using System.Collections;
public class hu : MonoBehaviour {
GameObject[] pauseObjects;
public bool isPaused;
void Start () {
pauseObjects = GameObject.FindGameObjectsWithTag("Player");
}
// Update is called once per frame
void Pause () {
{
if(Time.timeScale == 1)
{
Time.timeScale = 7f;
} else if (Time.timeScale == 8f){
Time.timeScale = 1;
}
}
}
}
Answer by Dream_in_code · Sep 11, 2016 at 06:08 AM
Void pauseGameobject()
{
if(//give your condition when or how will the gameobject pause)
{
start coroutine("wait");
}
}
public ienumenator wait()
{
time.timescale = 0;
yield return new waitforsceonds(7);
time.timesale = 1;
}
time.timescale = 0 means it will stop everything which will be "pause" and time.timescale = 1 means it will "unpause." first it will pause then it will wait for 7 seconds then it will unpause again. Just use the idea and modify according to your game :)
if(//give your condition when or how will the gameobject pause) . I don't want the gameobject to be pause by keys . I want gameobject to pause on its own. What would an example I put in the if statement.
what do you mean by pause by itself? just you play the game and player pauses itself? there is no sense in that. The conditions i mean are if he touches something or he goes to anther level etc.
I having a countdown numbers in the game . I want the player to be a pause until the countdown is over. That's why.
Your answer
Follow this Question
Related Questions
Pausing the game after player gets destroyed 1 Answer
Freezing Prefab or deactivating its script in another? 0 Answers
Enable/disable is not working as expected 2 Answers
Issues Pausing My App 1 Answer
How Can I Create My Own Textures? 3 Answers