Issues trying to activate an image through OnTriggerEnter/Exit/Stay(Flickering)
Hello!
I've been having this issue in my game for quite some time. I have looked on many forums and no answer seemed to fit my case, nor can I really understand what is happening. Perhaps you gus can help me!
So I have a simple script, and a simple function I want it to perform. Whenever my character gets near an NPC(holding this script), an icon will show up in the UI with the button the player should press to talk to the character. It is a 3D game. Here is the script that matters, it is in portuguese but that should be ok:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ColidindoTrigger : MonoBehaviour
{
public string TagOutro;
private Image BotaoE;
void Start()
{
BotaoE = GameObject.Find("UI_Icone_Conversa").GetComponent<Image>();
}
void OnTriggerStay(Collider outro) {
if (outro.tag == TagOutro)
{
BotaoE.enabled = true;
}
}
void OnTriggerExit(Collider outro)
{
if (outro.tag == TagOutro)
{
BotaoE.enabled = false;
}
}
}
Now, it "works", but the image itself flickers at random intervals with no discernible cause. There is only one trigger with the specified tag in the player. I have tried using OnTriggerEnter as well, to no avail. Has this got something to do with the physics engine? I believe my configurations are standard:
Before I used "enabled", I was using "SetActive" directly from a referenced parent. Same issue.
So, what's the diagnosis, friends? Is she gonna live??
Thanks as always for the help!
Hello my friend. I have the same issue. Did you manage to solve this? Bill
Never $$anonymous$$d i found it. $$anonymous$$y sword was colliding with my ui panel so in layer mask i disabled collisions between sword and panel.
Answer by KonniosGames · Apr 22, 2020 at 02:04 PM
I don't have much time so as far as I understand, you should maybe try replace OnTriggerStay() with OnTriggerEnter()
I've tried that, as stated in the original post. It doesn't seem to change anything.