Hello to everyone I create to simple scripts to read a note. and it works when press button char start to read a note.
Problem is note GUI don’t disappear when pressing actButton again, can anyone please help to figure what I am doing wrong?
Pick UP the note script:
public float RayDistance = 2f;
Camera MainCamera;
public GUISkin skin;
private bool readingNote = false;
private string noteText;
// 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"))
{
readingNote = true;
noteText = hit.collider.gameObject.GetComponent<NotePaper>().NoteText;
}
else
{
readingNote = false;
}
}
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);
}
}
}
And a Note it self 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";
}
}