상세 컨텐츠

본문 제목

[Unity] 자주쓰는 함수_(4) OnMouse

Unity

by 메타샤워 2023. 7. 19. 15:24

본문

유니티를 사용하다보면 마우스로 조작을 해야할 때가 잇다.

그럴때 간단하게 효과를 줄수 있는 기능을 소개하고자 한다. 버튼 부분에 응요하면 되겠다.
public class Button1 : MonoBehaviour {
 
    public Color OriginColor; //본래 자신의 색상.
 
    void Start () {
        OriginColor = guiTexture.color;
    }
 
    void OnMouseEnter(){ //마우스를 guiTexture에 올려 논 상태라면, 색상이 빨갛게 변함.
        guiTexture.color = Color.red;
    }
    void OnMouseExit(){  //마우스를 guiTexture에 올려 논 상태가 아니라면, 색상이 본래 자신의 색상으로 변함.
        guiTexture.color = OriginColor;
    }
     
    void OnMouseDown(){ //마우스로 guiTexture를 클릭했을 경우, 색상이 파랗게 변함.
        guiTexture.color = Color.blue;
    }
}

관련글 더보기