- Home /
Interacting with sign, canvas lags when activating.
So I have a script where when I get into the radius of my sign an image of the keyboard letter "E" will pop up so the player knows that they need to press "E" to interact. Once they do interact, I activate two items that are on a canvas, and which are disabled before the game even starts. Once they press "E" the signs background UI pops up(The color behind the text), and the signs text itself pops up. The only problem is that when you press "E" the game freezes for about 2 seconds and then the UI pops up. But keep in mind that it does not lag in Unity itself, only in the build, and I have tried it on multiple computers, so it's not just mine acting up.
My question is, is there any way to make UI pop up smoothly and not make the game lag? I know you could try putting it on a different layer and just switch layers when they interact(I think that works), but are there any other ways? Thank you for any help that I get. :)
Also, here is the script for the sign: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Signs : MonoBehaviour {
[SerializeField]
private GameObject signText;
[SerializeField]
private GameObject signBackground;
private bool signOpen;
private bool inRadius;
[SerializeField]
private Transform player;
private float distance;
[SerializeField]
private float distanceUntilInteraction;
[SerializeField]
private GameObject eImage;
// Update is called once per frame
void Update () {
distance = Vector3.Distance(transform.position, player.position);
if (distance < distanceUntilInteraction)
{
inRadius = true;
eImage.SetActive(true);
}
else
{
inRadius = false;
eImage.SetActive(false);
}
if (Input.GetKeyDown("e") && signOpen == false && inRadius == true)
{
signText.SetActive(true);
signBackground.SetActive(true);
signOpen = true;
}
else if (Input.GetKeyDown("e") && signOpen == true || inRadius == false)
{
signText.SetActive(false);
signBackground.SetActive(false);
signOpen = false;
}
}
}
the easiest would be to create a development build with auto attach profiler option and then running it on the target device. the profiler should spike the moment it lags.you should then be able to see what's causing the performance impact in the Profiler