기존 문제점: 이미지가 여러개로 구성된 버튼의 경우 버튼 색 변화에 문제점이 있다.

예시: 기존이 왼쪽, 변경된 것이 오른쪽



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CombinedButtonHover : MonoBehaviour
{
 
    [SerializeField]
    private List<Image> images;
 
    [SerializeField]
    private Color color;
    [SerializeField]
    private Color pressedColor;
    
    public bool isBeingMouse;
 
    [Header("Fade")]
    [SerializeField] private float fadeDuration = 0.12f;
 
    private Coroutine fadeRoutine;
 
    #region buttonColor
    public void enter()
    {
        isBeingMouse = true;
        // 마우스가 CombinedButton 위에 있을 때의 동작
        FadeTo(color);
    }
    public void exit()
    {
        isBeingMouse = false ;
        // 마우스가 CombinedButton에서 나갔을 때의 동작
        FadeTo(Color.white);
    }
    public void mouseDown()
    {
        FadeTo(pressedColor);
    }
    public void mouseUp()
    {
        FadeTo(isBeingMouse ? color : Color.white);
    }
    #endregion
    private void FadeTo(Color target)
    {
        if (fadeRoutine != null) StopCoroutine(fadeRoutine);
        fadeRoutine = StartCoroutine(FadeImages(target, fadeDuration));
    }
 
    private IEnumerator FadeImages(Color target, float duration)
    {
        if (images == null || images.Count == 0) yield break;
 
        Color[] starts = new Color[images.Count];
        for (int i = 0; i < images.Count; i++)
            if (images[i] != null) starts[i] = images[i].color;
 
        float t = 0f;
        while (t < duration)
        {
            t += Time.unscaledDeltaTime;
            float k = duration <= 0f ? 1f : Mathf.Clamp01(t / duration);
 
            for (int i = 0; i < images.Count; i++)
            {
                if (images[i] == nullcontinue;
                images[i].color = Color.Lerp(starts[i], target, k);
            }
 
            yield return null;
        }
 
        for (int i = 0; i < images.Count; i++)
            if (images[i] != null) images[i].color = target;
    }
}
 
cs





사용법 

1. 부모 오브젝트에 CombinedButtonHover랑 EventTrigger올리고

2. Images에 통합할 이미지 전부 넣고

3.자기 취향따라 Color 정해주고,

4.EventTrigger에 사진처럼 넣어주고. 단 3번째의 pointerClick은 눌러서 실행시킬 함수를 넣으면 됨 ^^

2fbcde22ecd139ab2eed86e7409c746fe64d016d9ebe68e644b87589249bbfdae7149225fe4813e2cad8556d0677109c



실행 예시 ^^



단점 navigation 안됨 ㅠㅠ