반응형
Material 의 SurfaceType 이 Transparent 이어야 알파값을 적용할 수 있습니다.
URP 기준 Material를 UI/Unlit/Transparent로 생성후 Tint의 Alpha 값을 변경하면 됩니다.
- 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Example : MonoBehaviour
{
Material material;
float alpha = 0;
private void Awake()
{
material = GetComponent<Material>();
material.color = new Color(color.r, color.g, color.b, alpha / 255);
}
}
- 일정 주기로 깜빡거리게 하기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Example : MonoBehaviour
{
public Color color;
Material material;
public float changeSpeed = 60;
float tt = 0;
bool change = false;
private void Awake()
{
material = GetComponent<Material>();
}
private void OnEnable()
{
StartCoroutine(ChangeAlphaCoroution());
}
private void OnDisable()
{
StopAllCoroutines();
}
IEnumerator ChangeAlphaCoroution()
{
while(true)
{
if (!change)
{
tt += 1;
if (tt >= changeSpeed)
{
change = true;
}
}
else
{
tt -= 1;
if (tt <= 0)
{
change = false;
}
}
material.color = new Color(color.r, color.g, color.b, tt / changeSpeed);
yield return new WaitForSeconds(0.01f);
}
}
}
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 시스템 언어 가져오기 System Language 간단 사용법 (0) | 2022.07.06 |
---|---|
유니티 C# 플랫폼 분기별 코드 작성하기 Platform 간단 사용법 (0) | 2022.07.06 |
유니티 C# 공전, 자전 간단 구현 Revolution (0) | 2022.07.05 |
유니티 C# 스킨드 메쉬 랜더러 Blend Shape 설정 간단 사용법 (0) | 2022.07.05 |
유니티 C# 비동기 프로그래밍 Task 간단 사용법 (0) | 2022.06.30 |
유니티 C# 인터페이스 Interface 간단 사용법 (0) | 2022.06.30 |
유니티 C# 시스템 액션 System.Action 간단 사용법 (0) | 2022.06.30 |
유니티 C# 버튼 리스너 onClick AddListener 추가 간단 사용법 (0) | 2022.06.30 |
댓글