Shader "Custom/whiteShader"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_TintColor("Tint Color", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderType" = "Transparent" "RenderType" = "Opaque" }
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 texColor = tex2D(_MainTex, i.uv);
fixed4 finalColor;
finalColor.rgb = _TintColor.rgb;
finalColor.a = texColor.a * _TintColor.a;
return finalColor;
}
ENDCG
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIExpSlideDirector : MonoBehaviour
{
public Slider sliderExp;
public Text txtExp;
public Image imgFill;
private float blinkDelay = 0.1f;
private Material originMaterial;
[SerializeField]
private Material whiteMaterial;
private Coroutine blinkRoutine;
public void Init()
{
this.originMaterial = this.imgFill.material;
}
public void BlinkEXPFill()
{
if (this.blinkRoutine != null) StopCoroutine(this.blinkRoutine);
this.blinkRoutine = StartCoroutine(this.BlinkRoutine());
}
private IEnumerator BlinkRoutine()
{
this.imgFill.material = this.whiteMaterial;
yield return new WaitForSeconds(this.blinkDelay);
this.imgFill.material = this.originMaterial;
}
}
유니티 이미지가 흰색이 아니라면 Color 값을 활용하여 원하는 색상으로 변경할 수 없습니다.. 해당 문제를 해결하기 위해 Shader를 만들어 필요할 때 원하는 Shader를 적용하는 방식으로 이미지 색상을 변경하였습니다. 해당 기능은 좌상단의 EXP, Healthbar UI에 적용하였습니다.
'Unity2D' 카테고리의 다른 글
Unity) [UGUI] 버튼을 누르고 있으면 연속으로 값이 상승하는 버튼 구현 (0) | 2023.05.17 |
---|---|
Unity) [유니티 2D] Glow 효과 (0) | 2023.05.17 |
Unity) [UGUI] 터치하면 팝업, 터치를 떼면 팝업이 꺼지는 기능 구현 (0) | 2023.05.14 |
Unity) [유니티 2D] 터치 기준 조이스틱 이동시키기 (0) | 2023.05.14 |
Unity) [유니티 2D] 타일맵 Collider 사이즈 관련 (0) | 2023.05.08 |