Hey guys!
So I’ve created a pause function for my game within a clock script. And now I have every object or asset that I want paused outside of the Time.Scale feature to access this script.
Everything I’ve wanted to pause so far, will pause…except this script. I for the life of me cannot get this sucker to pause and resume on command.
#pragma strict
import SmoothMoves;
var resourceValue: int = 25;
var Countdown: int = 5;
var visible: float = 0.50;
var invisible: float = 0.50;
var blinkFor: float = 5.0;
var myAnimation: SmoothMoves.BoneAnimation;
var getPlayTime: float = 0.0;
private var spawn: boolean = true;
private var startState: boolean = true;
private var startBlink: boolean = true;
var getPlayTimeEnabled: boolean = true;
private var getClock: GameObject;
var whenAreWeDone: float = 0.0;
function Start ()
{
getClock = GameObject.FindGameObjectWithTag("clock");
}
function Update ()
{
getPlayTime = getClock.GetComponent(clock).playTime;
getPlayTimeEnabled = getClock.GetComponent(clock).playTimeEnabled;
if (getPlayTimeEnabled)
{
myAnimation["Idle"].speed = 1;
myAnimation["Spawn"].speed = 1;
//renderer.enabled = true;
}
else
{
myAnimation["Idle"].speed = 0;
myAnimation["Spawn"].speed = 0;
//renderer.enabled = false;
}
if (startBlink && getPlayTimeEnabled)
{
Blink ();
startBlink = false;
}
}
function Spawn ()
{
animation.Play("Spawn");
yield WaitForSeconds (1);
startBlink = true;
}
function Blink ()
{
whenAreWeDone = getPlayTime + blinkFor;
animation.Play("Spawn");
yield WaitForSeconds (1);
animation.Play("Idle");
renderer.enabled = startState;
yield WaitForSeconds(Countdown);
if (getPlayTimeEnabled)
{
while (getPlayTime < whenAreWeDone)
{
if ( startState )
{
renderer.enabled = false;
yield WaitForSeconds(invisible);
renderer.enabled = true;
yield WaitForSeconds(visible);
}
else
{
print ("in else");
renderer.enabled = true;
yield WaitForSeconds(visible);
renderer.enabled = false;
yield WaitForSeconds(invisible);
}
}
renderer.enabled = true;
Destroy ( gameObject );
}
}
It’s basically an object that, after it is instantiated, will flash after some time…then destroy itself.
The problem I’m having is, I cannot get it to pause during the flash. (when the code is in the while statement) As you can see I have a global boolean that would detect if the game has been paused, “playTimeEnabled”. And a float that represents the game’s Time.time. “playTime”.
If anyone has any ideas, I’m open to suggestions.