Search Unity

Basic In Game Pause Menu Script Problems

Discussion in 'Scripting' started by JallasZA, Dec 19, 2017.

  1. JallasZA

    JallasZA

    Joined:
    Oct 28, 2017
    Posts:
    1
    Good Day,

    First Off, Here is the code I am having trouble with:
    -----------------------------------------------------------------------------------------------------------------------------------------------
    using System.Collections;
    using UnityEngine;
    using UnityStandardAssets.Characters.FirstPerson;

    public class Pause : MonoBehaviour
    {
    public Transform canvas;
    public GameObject Player;

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.Escape))
    {
    if (canvas.gameObject.activeInHierarchy == false)
    {
    canvas.gameObject.SetActive(true);
    Time.timeScale = 0;
    Player.gameObject.SetActive(false);
    Cursor.visible = true;
    }
    else
    {
    canvas.gameObject.SetActive(false);
    Time.timeScale = 1;
    Player.gameObject.SetActive(true);
    Cursor.visible = false;
    }
    }

    }
    }
    ------------------------------------------------------------------------------------------------------------------------------------------------

    The Problem I am Facing is that whenever I open the in game menu There appears to be a shadow effect (Ghosting) on my character while moving.

    Is the a way to "freeze" all my character inputs Instead of needing to deactivate and reactivate, as it seems to be giving me troubles?

    Kind Regards
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
  3. hasanbayat

    hasanbayat

    Joined:
    Oct 18, 2016
    Posts:
    630
    Here is the code using code tags:
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityStandardAssets.Characters.FirstPerson;
    4.  
    5. public class Pause : MonoBehaviour
    6. {
    7.    
    8.     public Transform canvas;
    9.     public GameObject Player;
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         if (Input.GetKeyDown(KeyCode.Escape))
    15.         {
    16.             if (canvas.gameObject.activeInHierarchy == false)
    17.             {
    18.                 canvas.gameObject.SetActive(true);
    19.                 Time.timeScale = 0;
    20.                 Player.gameObject.SetActive(false);
    21.                 Cursor.visible = true;
    22.             }
    23.             else
    24.             {
    25.                 canvas.gameObject.SetActive(false);
    26.                 Time.timeScale = 1;
    27.                 Player.gameObject.SetActive(true);
    28.                 Cursor.visible = false;
    29.             }
    30.         }
    31.     }
    32.    
    33. }