Context:
I’m making a 2D rpg and I’ve got an issue with damage numbers(numbers that should appear where the weapon hits an enemy and then float up and disappear after a few updates).
Damage number is a canvas prefab with a child text gameobject;
To create the damageNumber I’m using this command:
var clone=(GameObject)Instantiate(damageNumber,hitPoint.position,Quaternion.Euler(Vector3.zero));
where damageNumber is the canvas with the damage numbers,and hitPoint is an empty gameobject child of the weapon from which damage numbers should spawn,but instead they keep spawning at x:0 y:0 z:0 and then float up.
Here’s the script that makes the numbers float up(attached to the canvas)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FloatingNumbers : MonoBehaviour {
public float moveSpeed;//speed at which the number goes up
public int damageNumber;//damage number shown
public Text displayNumber;//refers to the text box child of the canvas
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
displayNumber.text = "" + damageNumber;//shows damage number in the textbox
transform.position=new Vector3(transform.position.x,transform.position.y+(moveSpeed*Time.deltaTime), transform.position.z);//makes the number go up.I think that the problem may be here;
}
}
Sorry for bad English
I’m not a native speaker