So I want to make Damage pop up and move it like Diablo3’s damage effects.
So I wrote code like
public GameObject damagePrefab;
public Transform damageTransform;
public int tempDam;
public Canvas mainCanvas;
void Start() {
}
void Update() {
if (Input.GetKeyDown("q")) {
CreateDamagePopup(tempDam);
}
}
public void CreateDamagePopup(int damage) {
GameObject damgo = (GameObject) Instantiate(damagePrefab, damageTransform.position,
damageTransform.rotation);
damgo.GetComponentInChildren<Text>().text = damage.ToString();
damgo.transform.parent = mainCanvas.transform;
damgo.transform.localPosition = new Vector3(0, 0, 0);
damgo.GetComponent<Animation>().Play();
}
But animation does not played after instantiate prefab.
Why?