Hello to everyone, please help how can I pause a game when reading note and stop player from moving, and unpause the game when player stops reading a note?
Taking Note Script:
public class TakeAnote : MonoBehaviour {
public float RayDistance = 2f;
Camera MainCamera;
public GUISkin skin;
private bool readingNote = false;
private string noteText;
protected bool pause = false;
// Use this for initialization
void Start () {
MainCamera = GetComponent<Camera>();
}
// Update is called once per frame
void Update () {
RaycastHit hit;
Ray ray = GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
if (Physics.Raycast(ray, out hit, RayDistance))
{
if (hit.transform.gameObject.tag == "Note")
{
if (Input.GetButtonDown ("actButton"))
{
Time.timeScale = 0;
readingNote = !readingNote;
noteText = hit.collider.gameObject.GetComponent<NotePaper>().NoteText;
}
else if (Input.GetButtonDown("actButton"))
{
Time.timeScale = 1;
}
}
Debug.Log("Hit Note");
}
}
void OnGUI()
{
if (skin)
GUI.skin = skin;
//Are we reading a note? If so draw it.
if (readingNote)
{
//Draw the note on screen, Set And Change the GUI Style To Make the Text Appear The Way you Like (Even on an image background like paper)
GUI.Box(new Rect(Screen.width / 4F, Screen.height / 16F, Screen.width / 2F, Screen.height * 0.75F), noteText);
}
}
}
Note Script
public class NotePaper : MonoBehaviour {
public string NoteText = "Enter Your Text";
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.name = "Note";
}
}