Hello I have 3 objects that have attached same script, this script calls and UI text when player triggers the collider, but this only works with one of the three objects, anyone knows why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class abrirPuerta : MonoBehaviour
{
public Text abrirPuertaText;
public Animator puerta;
private bool show;
public AudioClip pulsarBotonAudio;
public AudioClip abrirPuertaAudio;
private AudioSource audioSetup;
void Start()
{
abrirPuertaText.text = "";
show = false;
puerta.SetBool("on", false);
audioSetup = GetComponent<AudioSource>();
}
private void Update()
{
if (show)
{
abrirPuertaText.text = "Pulsa 'E' para abrir la puerta.";
}
else
{
abrirPuertaText.text = "";
}
if (Input.GetKeyDown(KeyCode.E) && show == true && puerta.GetBool("on") == false)
{
audioSetup.PlayOneShot(pulsarBotonAudio);
audioSetup.PlayOneShot(abrirPuertaAudio);
puerta.SetBool("on", true);
}
else
{
if (Input.GetKeyDown(KeyCode.E) && show == true && puerta.GetBool("on") == true)
{
audioSetup.PlayOneShot(pulsarBotonAudio);
audioSetup.PlayOneShot(abrirPuertaAudio);
puerta.SetBool("on", false);
}
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
show = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
show = false;
}
}
}