HUDTest
Unity/수업내용 2019. 4. 25. 09:551 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 51 52 53 54 55 56 | using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TestHudText : MonoBehaviour { public Button btn; private Canvas canvas; private void Awake() { this.canvas = FindObjectOfType<Canvas>(); } private void Start() { //DOTween.To(MyMethod, 0, 12, 0.5f); this.btn.onClick.AddListener(() => { Debug.Log("앙기모띠"); //프리팹 로드 var hudPre = Resources.Load<HUDDamageText>("Prefabs/Test/HUDDamageText"); //인스탄트 var hud = Instantiate(hudPre); //인잇 메서드 호출(텍스트랑 컬러) Color color = new Color(1, 0, 0); hud.Init("456", color); //부모 Canvas로 설정 hud.transform.SetParent(this.canvas.transform, false); //초기화 hud.transform.localPosition = Vector3.zero; //타겟 포지션 var targetLocalPos = hud.transform.localPosition; targetLocalPos.y += 200; DOTween.ToAlpha(() => hud.txt.color, x => hud.txt.color = x, 0, 0.5f); hud.transform.DOScale(new Vector3(2, 2, 2), 0.3f).OnComplete(() => { hud.transform.DOScale(new Vector3(1, 1, 1), 0.2f); }); hud.transform.DOLocalMove(targetLocalPos, 0.5f).SetEase(Ease.OutCirc).OnComplete(() => { Destroy(hud.gameObject); }); }); } } | cs |
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; using UnityEngine.UI; public class HUDDamageText : MonoBehaviour { //문자, 컬러 public Text txt; public void Init(string strDamage, Color color) { this.txt.text = strDamage; this.txt.color = color; } } | cs |
'Unity > 수업내용' 카테고리의 다른 글
(1)BGLoop (0) | 2019.05.01 |
---|---|
LayerMask (0) | 2019.05.01 |
자습서1(WASD이동, 마우스 포인트 Look, 라인렌더링 (0) | 2019.04.30 |
<캐릭터 조작>화면 터치, WASD, 조이스틱 (0) | 2019.04.25 |
<죽어라돌덩이> (0) | 2019.04.12 |