Get it on Google Play


Wm뮤 :: 유니티 킬로그

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


2023. 8. 28. 04:34 Unity

 

 

KillPeed 라고도 한다

어려운건 아닌데 ㅈㄴ 귀찮다

계층구조는 이렇고

컴포넌트는 하단처럼 심어주자

 

사용된 코드는 이 두개

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class KillPeed : MonoBehaviour
{
    public KillPeedSlot killPeedSlotPrefab;
    List<KillPeedSlot> killPeedSlots= new List<KillPeedSlot>();
    public float displayTime = 5; //5초후삭제
    public Color enemyColor=Color.red;
    public Color allyColor = Color.blue;
    // Start is called before the first frame update
    void Start()
    {
        killPeedSlotPrefab.gameObject.SetActive(false);
    }
    public void Add(string source, string target,Sprite icon, Color sourceColor, Color targetColor, bool critical = false, bool highlight=false)
    {
        killPeedSlots = killPeedSlots.FindAll(x => x != null);//시간경과로 지워진건 제외
        if (killPeedSlots.Count>=3)//3칸 넘으면 오래된거 삭제
        {
            Destroy(killPeedSlots[0].gameObject);
        }

        var instant = Instantiate(killPeedSlotPrefab, killPeedSlotPrefab.transform.parent);
        instant.source.color = sourceColor;
        instant.target.color = targetColor;
        instant.source.text = source;
        instant.target.text = target;
        instant.icon.sprite = icon;
        instant.critical.SetActive(critical);
        instant.gameObject.SetActive(true);
        if (highlight)
        {
            instant.Highlight();
        }
        Destroy(instant.gameObject, displayTime); 
        killPeedSlots.Add(instant);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class KillPeedSlot : MonoBehaviour
{
    public Text source;
    public GameObject critical;
    public Image icon;
    public Text target;
    void Update()
    {
        GetComponent<ContentSizeFitter>().enabled = false;
        GetComponent<ContentSizeFitter>().enabled = true;
    }
    public void Highlight()
    {
        var color = GetComponent<Image>().color;
        color.r = 1f- color.r;
        color.g = 1f - color.g;
        color.b = 1f - color.b;
        GetComponent<Image>().color = color;
        icon.color = Color.black;
    }
}

 

'Unity' 카테고리의 다른 글

유니티 APK 용량  (0) 2023.09.08
유니티 플랫폼 훅  (0) 2023.08.23
유니티 웨이포인트식 자율주행  (0) 2023.08.19
posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입