DOTween(캐릭터 공격력 효과)
2020. 5. 25. 15:12
728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HudTextTest : MonoBehaviour
{
public UIHudTextTest uiHudTextTest;
public Transform pivotTrans;
void Start()
{
this.uiHudTextTest.btn.onClick.AddListener(() =>
{
this.uiHudTextTest.ShowHud(this.pivotTrans.position, 5000);
});
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIHudText : MonoBehaviour
{
public Text text;
public void Init(string strNum, Vector2 targetLocalPos)
{
this.text.text = strNum;
this.transform.localPosition = targetLocalPos;
}
}
|
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
|
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class UIHudTextTest : MonoBehaviour
{
public Button btn;
public GameObject uiHudTextPrefab;
// targetPos : wordl position
public void ShowHud(Vector3 targetPos, int num)
{
var strNum = string.Format("{0:#,0}", num); // 세자리수',' + {0:#,###}
Debug.LogFormat("{0}", strNum);
var hudTextGo = Instantiate<GameObject>(this.uiHudTextPrefab);
hudTextGo.transform.SetParent(this.transform, false);
var pos = Camera.main.WorldToScreenPoint(targetPos);
var canvasPosX = pos.x - 1920 / 2;
var canvasPosY = pos.y - 1080 / 2;
// 초기 위치 설정
var targetLocalPos = new Vector2(canvasPosX, canvasPosY);
var uiHudText = hudTextGo.GetComponent<UIHudText>();
uiHudText.Init(strNum, targetLocalPos);
hudTextGo.transform.localScale = Vector3.zero;
var targetPosY = hudTextGo.transform.localRotation.y + 100;
hudTextGo.transform.DOScale(2f, 0.5f).OnComplete(() =>
{
hudTextGo.transform.DOScale(0, 0.5f).OnComplete(() =>
{
});
});
hudTextGo.transform.DOLocalMoveY(targetPosY, 1f).SetEase(Ease.OutQuint).OnComplete(() =>
{
Debug.Log("Move complete");
Object.Destroy(hudTextGo);
});
}
}
|
cs |
728x90
'Unity > Study' 카테고리의 다른 글
Coroutine (0) | 2020.05.26 |
---|---|
DrawWireArc(Attack arange) (0) | 2020.05.25 |
Box Colider (0) | 2020.05.25 |
Atlas (0) | 2020.05.21 |
Main Camer, UI Camera (0) | 2020.05.21 |