- Home /
Game stops for a few seconds after interacting with an object
Hi there, im trying to establish a system for object interaction, but every time player goes inside the trigger and i press "E" the game stops for a few seconds and then the UI dialog appears, this only appens the first time i try to do this. I would really appreciate any coments on this. I place this script into the object: using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Object_Interaction_Dialog : MonoBehaviour
{
public string[] _Dialog_Database;
public int _Speech_Number = 0;
public Text _Dialog;
public GameObject _Dialog_Box;
public ThirdPersonMovement _ThirdPersonMovement_Script;
public void Dialog_With_Gate()
{
if (_Speech_Number < _Dialog_Database.Length)
{
_Dialog.text = _Dialog_Database[_Speech_Number];
}
else
{
_Dialog.text = "";
_Speech_Number = 0;
_Dialog_Box.SetActive(false);
_ThirdPersonMovement_Script.enabled = true;
}
_Speech_Number++;
}
public bool inTrigger;
void OnTriggerEnter(Collider other)
{
inTrigger = true;
}
void OnTriggerExit(Collider other)
{
inTrigger = false;
}
void Update()
{
if (inTrigger)
{
if (Input.GetKeyDown(KeyCode.E))
{
_ThirdPersonMovement_Script._Horizontal = 0;
_ThirdPersonMovement_Script._Vertical = 0;
_ThirdPersonMovement_Script.enabled = false;
_Dialog_Box.SetActive(true);
Dialog_With_Gate();
}
}
}
}
Look in your profiler and check what takes most CPU when you interact with the object. It's impossible to analyze otherwise.
I did, thanks. I think the dialog text has an issue appearing for the first time, in other words unity has problems showing the dialog text, it gets stuck for a few seconds and then it appears.
Answer by AncorG1985 · Aug 31, 2020 at 02:40 AM
The Issue was with the Font itself, i had no font added inside my project. Arial is the default font in unity and that was causing the trouble. I hope this is useful to somebody in the future.
Your answer
Follow this Question
Related Questions
GameObjects creation within boundry 3 Answers
Problem with timed code-execution (audioplay and object destruction) 1 Answer
MouseDown Triggered by Another GameObject 1 Answer
rigidbody.velocity not working on x axis 2 Answers
Sphere and Cube collision won't work,Sphere vs Cube collision won't work 1 Answer