观察者

2017-11-01  本文已影响0人  貪狼大人
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cube : MonoBehaviour {

    // Use this for initialization
    void Start () {
        NotificationCenter.Instance.RegistObserver("CubeAngry",ScaleSelf);
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    public void ScaleSelf(MesageInfo mesage)
    {
        transform.localScale = Vector3.one * (int)mesage.Alist[0];
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class sphere : MonoBehaviour
{
    MesageInfo mesage;
    void Awake()
    {
        NotificationCenter.Instance.RegistObserver("SphereAngry", ChangeColor);
        NotificationCenter.Instance.RegistObserver("SphereMove", Move);
    }
    public void ChangeColor(MesageInfo mesage)
    {
        GetComponent<MeshRenderer>().material.color = (Color)mesage.Alist[0];
    }
    public void Move(MesageInfo mesage)
    {
        transform.position += transform.forward * (float)mesage.Alist[0];
    }
}

上一篇下一篇

猜你喜欢

热点阅读