1
\$\begingroup\$

I've had a look around and kept finding about using Time.TimeScale = 0 to pause the game, although this is the normal way to do it, it is not exactly what im looking for.

When my menu button is pressed I have a texture which is instantiated and slides onto screen from the left side and therefore does not work with Time.TimeScale because the menu just stays hidden off scren.

Is there a way to have the game pause but still allow for this menu to slide onto screen?

Edit -

How I spawn in the Menu prefab (Within GameController Script):

public void MenuPressed ()
{
    Vector3 newPosition = new Vector3 (-13, -0.06f, -2);
    Quaternion newRotation = Quaternion.Euler (0, 0, 0);
    Instantiate (menu, newPosition, newRotation);

    menuButton.SetActive (false);

    textFrame.SetActive (true);
}

How I move the Menu (Within MenuMover Script):

void Start()
{
    rb = GetComponent<Rigidbody> ();

    rb.velocity = transform.right * speed;
}

void OnTriggerEnter (Collider other)
{
    if (other.tag == "MenuBoundary") 
    {
        rb.velocity = Vector3.zero;
    }
}

}

\$\endgroup\$
  • \$\begingroup\$ How are you sliding texture in screen? what piece of code are you using? \$\endgroup\$ – Hamza Hasan Mar 15 '16 at 10:59
  • \$\begingroup\$ On the MenuPressed I instantiate the Menu prefab, which has a script on there which moves it with this code rb.velocity = transform.right * speed \$\endgroup\$ – Weeksy Mar 15 '16 at 11:02
  • \$\begingroup\$ probably in update, right? Please update your question with full relative piece of code \$\endgroup\$ – Hamza Hasan Mar 15 '16 at 11:05
  • \$\begingroup\$ I've updated the question has suggested \$\endgroup\$ – Weeksy Mar 15 '16 at 11:08
1
\$\begingroup\$

You can use Coroutines for that. With WaitForEndOfFrame as it does not depend on Time.timeScale. What you have to do is to get rid of Rigidbody and Colliders.

So let say your menu Max X value (where it would stop actually) is 15. Then you can do with some code like,

// Script attached to your prefab

float _xLimit = 15;
float _speed = 0.1f;

void Start ()
{
    StartCoroutine ("MoveMenu");
}

IEnumerator MoveMenu ()
{
    while (true) {
        transform.position += Vector3.right * _speed;
        if (transform.position.x > _xLimit)
            yield break;
        yield return new WaitForEndOfFrame ();
    }
}
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Looks like you're attemnpting to use the physics engine in order to slide the text from left to right. The physics engine is paused effectively when you set the time scale to zero, so you'll need to slide your menu in without the aid of physics.

There are a couple of solutions you could try here:

The first is to use an animation on the object you want to slide across and set the animator controller's update to 'Unscaled Time' (http://docs.unity3d.com/ScriptReference/AnimatorUpdateMode.html)

The second is to move the menu transition to the Update loop (which is always called, even when the time scale is zero) and use Time.unscaledDeltaTime to keep the transition consistent (in this case you can change the transform position on each update)

As the physics engine is disabled you'll also need a new way to determine the boundary (as your trigger won't register). You could use something like the screen width or a game object position to determine when to stop in this instance... or if it's always a fixed width, just use that.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.