using AX.MessageSystem; using System.Collections; using System.Collections.Generic; using UnityEngine; public class TwinkleManager : MonoBehaviour { private Color VetOne = new Color(1,0, 0); private Color VetTwo = new Color(0.15f,0, 0); // Use this for initialization void Start () { MessageDispatcher.AddListener("StartTwinkle",StartTwinkle); MessageDispatcher.AddListener("StopTwinkle", StopTwinkle); StartCoroutine(Twinkle()); } private void OnDestroy() { MessageDispatcher.RemoveListener("StartTwinkle", StartTwinkle); MessageDispatcher.RemoveListener("StopTwinkle", StopTwinkle); } public void StartTwinkle(IMessage obj) { StartCoroutine(Twinkle()); } IEnumerator Twinkle() { while (true) { yield return new WaitForSeconds(0.5f); for(int i = 0; i < transform.childCount; i++) { TwinkleChildrenLines(transform.GetChild(i), VetOne); } yield return new WaitForSeconds(0.5f); for (int i = 0; i < transform.childCount; i++) { TwinkleChildrenLines(transform.GetChild(i), VetTwo); } } } void TwinkleChildrenLines(Transform trans,Color color) { for(int i = 0; i < trans.childCount; i++) { trans.GetChild(i).GetComponent().material.color = color; } } public void StopTwinkle(IMessage obj) { StopAllCoroutines(); } }