观察者

作者: 貪狼大人 | 来源:发表于2017-11-01 21:18 被阅读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];
        }
    }
    
    

    相关文章

      网友评论

          本文标题:观察者

          本文链接:https://www.haomeiwen.com/subject/lscnpxtx.html