-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDamageNumber.cs
50 lines (41 loc) · 1.48 KB
/
DamageNumber.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class DamageNumber : MonoBehaviour
{
public float damageSpeed;
public string damagePoints;
public Text damageText;
public TMP_Text damageTextPro;
public Vector2 direction = new Vector2(1, 0);
public float timeToChangeDirection = 1;
public float timeToChangeDirectionCounter = 1;
// Update is called once per frame
void Update()
{
timeToChangeDirectionCounter -= Time.deltaTime;
if (timeToChangeDirectionCounter < timeToChangeDirection / 2)
{
direction *= -1;
timeToChangeDirectionCounter += timeToChangeDirection;
}
if (damageText != null)
{
damageText.text = damagePoints;
}
if(damageTextPro != null)
{
damageTextPro.text = "" + damagePoints;
}
//this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + damageSpeed * Time.deltaTime,
// this.transform.position.z);
this.transform.position = new Vector3(
this.transform.position.x + direction.x * damageSpeed * Time.deltaTime,
this.transform.position.y + damageSpeed * Time.deltaTime,
this.transform.position.z
);
this.transform.localScale = this.transform.localScale * (1 - Time.deltaTime / 1.75f);
}
}