프로그래밍-1/Unity3D

Unity3D에서 자주 쓰고 있는 C# 코드 (4) - OnMouse (1)

daslyee 2013. 8. 19. 23:54
728x90
유니티를 사용하다보면 마우스로 조작을 해야할 때가 있다. 
그럴때 간단하게 효과를 줄수 있는 기능을 소개하고자 한다. 버튼 부분에 응용하면 괜찮을 거 같다.
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;
	}
}


728x90