I am trying to make a text box appear when I get close enough and left click. I can make the box appear, but I can’t figure out how to make it disappear. I know that it is probably something very simple, but i’m running low on time for my game. Does anyone know how to disable my text box?
The bottom part of my script is the part i’m having trouble with.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Camera_Raycast : MonoBehaviour {
private Camera _camera;
public RectTransform _rightLine;
public RectTransform _leftLine;
public RectTransform _topLine;
public RectTransform _bottomLine;
public Image chairBackground;
public Text chairText;
private bool chairInfoIsEnabled;
void Start() {
_camera = GetComponent<Camera> ();
chairBackground.enabled = false;
chairText.enabled = false;
}
void Update () {
Vector3 point = new Vector3 (_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0);
Ray ray = _camera.ScreenPointToRay (point);
RaycastHit hit;
chairInfoIsEnabled = false;
if (Physics.Raycast (ray, out hit, 5)) {
if (hit.collider.tag == "InspectableObject") {
_rightLine.localPosition = new Vector3 (5, 0, 0);
_leftLine.localPosition = new Vector3 (-5, 0, 0);
_topLine.localPosition = new Vector3 (0, 5, 0);
_bottomLine.localPosition = new Vector3 (0, -5, 0);
} else {
_rightLine.localPosition = new Vector3 (10, 0, 0);
_leftLine.localPosition = new Vector3 (-10, 0, 0);
_topLine.localPosition = new Vector3 (0, 10, 0);
_bottomLine.localPosition = new Vector3 (0, -10, 0);
}
if (hit.collider.tag == "InspectableObject" && hit.collider.name == "TestObject") {
if (Input.GetMouseButtonDown (0) && chairInfoIsEnabled == false) {
Debug.Log ("Activate Info");
chairBackground.enabled = true;
chairText.enabled = true;
chairInfoIsEnabled = true;
}
}
}
}
}
If you need any info, I’ll respond.