I am trying to show a text when i click on a ui button but i don't know how to implement this. On PC platform I have a collider per object and when the player stay and click the E button, a canvas text appear on screen, but i don't know how to do this on Android. I want something like Resident Evil old style action button, opening doors and getting object description. How could i do this?
The Script
public class readingNote : MonoBehaviour {
public AudioSource audio;
public AudioClip collectSound;
public bool playerNextToKey = false;
bool hasCollided = false;
public GameObject pic;
public GameObject text;
public GameObject notePad;
private Collider other;
// void Start () {
// pic.SetActive(false);
// text.SetActive (false);
//
// }
public Button yourButton;
void Start()
{
pic.SetActive(false);
text.SetActive (false);
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
//can't text.SetActive(true); because when i get out the scene, text is showing up (I use the same button to open doors and get text description).
}
void OnTriggerStay ( Collider other) {
if(other.gameObject.tag == "Player") {
//if(Input.GetKeyDown(KeyCode.E)) {
text.SetActive (true);
pic.SetActive(true);
AudioSource.PlayClipAtPoint(collectSound, transform.position);
//}
}
}
void OnTriggerExit ( Collider other )
{
if (other.gameObject.tag == "Player")
{
//enter = false;
//print("close");
playerNextToKey = false;
hasCollided = false;
pic.SetActive(false);
text.SetActive (false);
}
}
}