Answer the question
In order to leave comments, you need to log in
Unity why is OnTriggerStay causing a lot of lag?
i have a code
private void OnTriggerStay(Collider other)
{
if (enemy == null)
{
if (other.gameObject.tag == "Crip")
{
if (other.gameObject.GetComponent<Crip>().isMyTeam != gameObject.GetComponent<Crip>().isMyTeam)
{
enemy = other.transform;
prior = Priority.Enemy;
}
}
else
return;
}
else
return;
}
Answer the question
In order to leave comments, you need to log in
Because it GetComponent
is a heavy function, and every update you have it is called twice on each bot. You can save the gameObject InstanceId and if it has not changed, then there is nothing to run all this logic over again.
If your avatar is set through the img tag, then like this:
img {
object-fit: cover;
object-position: center;
}
.image {
background: url() no-repeat center;
background-size: cover;
}
set the parent to position: relative;
and ave
position: absolute;
top50%;
transition: translateY(-50%);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question