- Home /
Question by
ragefordragons · Mar 10, 2018 at 07:45 PM ·
instantiateprefabpositiontextdamage
Help making a damage number system
So i am attempting to make a damage number system that shows up when you hit an enemy. The code below belongs to the hitbox that shows up while you attack. What I want to do is instantiate a prefab (In this case its my text) and set its text to the damage delt, and then set its postion to the enemies position.
Any help doing this?
public class DamageNumbers : MonoBehaviour {
public GameObject damageText;
public Transform enemy;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("enemy"))
{
Instantiate(damageText, enemy.position, enemy.rotation);
}
}
}
Comment
Best Answer
Answer by ZeroGravity2000 · Mar 10, 2018 at 08:59 PM
Your question has been answered at least once, I bet many times. Look at this answer here:
https://answers.unity.com/questions/122479/attack-damage-scrolling.html
Also there is few YouTube tutorials shown here: