I have tried everything but it still doesn't work. I am not talking about implementing functions wich has stuff inside when you click the UI Button. I want literally replace this Input.GetKeyDown(KeyCode.E). That is inside an if statement and replace with the UI Button object. How can i do this? I have tried with GetButton, GetButtonDown, trying to give a name and with Input.touchCount>0
I am developing a game like Resident Evil old style and when you enter a triggerStay and push the button, a text is showing up.
The Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine;
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;
public Button yourButton;
void Start()
{
pic.SetActive(false);
text.SetActive (false);
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
/*THIS IS SHOWING ALL TEXT IN THE SCENE AND NOT ONE BY ONE WHEN PRESSING*/
// text.SetActive (true);
// pic.SetActive(true);
}
void OnTriggerStay ( Collider other) {
if(other.gameObject.tag == "Player") {
if(Input.GetKeyDown(KeyCode.E)) {
//if(Input.touchCount>0) {
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);
}
}
}