- Home /
Question by
hashtaghashtag · Mar 10, 2017 at 07:04 AM ·
c#pause menu
pause screen problem
I am experiencing a problem with my pause screen I used some recommended code to create a system to delay the pausing of my game by one second to allow a pause animation to take place however it continuously loops in and out of the animation once I press escape once the animation is not set to loop I know its a problem in the script because when I look In the animator while this is occurring it displays the animation switching between my idle and the pause animation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pause : MonoBehaviour {
public bool pauseg;
private Animator anim;
bool paused = false;
void Start()
{
anim = gameObject.GetComponent<Animator>();
}
void Update()
{
anim.SetBool("Pause", pauseg);
if (Input.GetKeyDown(KeyCode.Escape))
{
paused = true;
}
if (paused){
if (Time.timeScale == 0f)
{
Time.timeScale = 1f;
pauseg = false;
paused = false;
}
else
{
pauseg = true;
paused = false;
}
}
}
IEnumerator processTask()
{
yield return new WaitForSeconds(1);
if (paused && Time.timeScale == 1f)
{
Time.timeScale = 0f;
paused = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Time.timeScale doesnt work with GUI? 0 Answers
GUIButton menu is in wrong place in built version of my game 0 Answers