델리게이트 연습 소스
using UnityEngine;
using System.Collections;
delegate void EventHandler( Color color );
class OrcParams
{
public event EventHandler OnColorChange;
int _hp = 100;
public int hp{
get {
return _hp;
}
set{
_hp = value;
if (_hp < 50)
OnColorChange (Color.red);
}
}
}
public class test : MonoBehaviour {
GameObject ttt;
void ChangeColor(Color color)
{
gameObject.GetComponent<MeshRenderer>().material.color = color;
}
void ShowColorValue (Color color){
Debug.Log (color);
}
OrcParams MyParam;
void Start ()
{
MyParam = new OrcParams();
MyParam.OnColorChange += ShowColorValue;
MyParam.OnColorChange += ChangeColor;
}
void OnMouseDown()
{
MyParam.hp -= 10;
//Debug.Log (MyParam.hp);
}
void Update ()
{
}
}
using System.Collections;
delegate void EventHandler( Color color );
class OrcParams
{
public event EventHandler OnColorChange;
int _hp = 100;
public int hp{
get {
return _hp;
}
set{
_hp = value;
if (_hp < 50)
OnColorChange (Color.red);
}
}
}
public class test : MonoBehaviour {
GameObject ttt;
void ChangeColor(Color color)
{
gameObject.GetComponent<MeshRenderer>().material.color = color;
}
void ShowColorValue (Color color){
Debug.Log (color);
}
OrcParams MyParam;
void Start ()
{
MyParam = new OrcParams();
MyParam.OnColorChange += ShowColorValue;
MyParam.OnColorChange += ChangeColor;
}
void OnMouseDown()
{
MyParam.hp -= 10;
//Debug.Log (MyParam.hp);
}
void Update ()
{
}
}
댓글
댓글 쓰기