Simple POP UP Damage Script-Animation
Hi guys i am facing a perfomance problem and i dont know the reason is someone can see the code and answer me it will be helpful , I am trying to make a simple script that pop up the damage that you get like the photo below , the problem is that is working fine but i think is getting a bit laggy over time, i am creating i 3d text object that shows the damage and then i destroy it , because you can get multiple hits (creating multiple 3dtext object and then destroy it ) .
public void PopUpDamage(float amount)
{
float currentTimeMillisecond = Time.time * 1000;
Vector3 positionPrefab3DText = m_3DTextPrefab.transform.position;
GameObject gameObject3DText =null;
if ((currentTimeMillisecond - m_PreviousTimerMilisecond) > 1500 || m_EscalateTimes > 5) // If escalates 5 Times or time passed :: 1500 millisecond reset :: Starts From The Bottom ::
{
//Reset
gameObject3DText = Instantiate(m_3DTextPrefab, positionPrefab3DText, m_3DTextPrefab.transform.rotation) as GameObject;
m_PreviousTimerMilisecond = currentTimeMillisecond;
m_EscalateY3DText = positionPrefab3DText.y;
m_EscalateTimes = 0;
}
else {
m_EscalateY3DText += 0.5f; //escalate Y = 0.5 Every Loop
positionPrefab3DText = new Vector3(positionPrefab3DText.x, m_EscalateY3DText, positionPrefab3DText.z);
m_PreviousTimerMilisecond = currentTimeMillisecond;
//Anime The Damage
gameObject3DText = Instantiate(m_3DTextPrefab, positionPrefab3DText, m_3DTextPrefab.transform.rotation) as GameObject;
m_EscalateTimes += 1;
}
TextMesh m_3DTextMesh = gameObject3DText.GetComponent<TextMesh>();
m_3DTextMesh.text = "-" + amount + " HP";
Destroy(gameObject3DText, 0.5f); // Destroy 3d Text in 0.5
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612084040im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
any physical/practical limit to number of lights in view? 0 Answers
Low performance on Mobile build of 2D Platformer game. 1 Answer
Is UI system much worse in terms of performance than using 2D sprite? 0 Answers
Why is my Custom Inspector Causing Performance Issues? 0 Answers
Different pc performance problem 0 Answers