You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.6 KiB
53 lines
1.6 KiB
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<Renderer>().material.color = color; |
|
} |
|
} |
|
public void StopTwinkle(IMessage obj) |
|
{ |
|
StopAllCoroutines(); |
|
} |
|
}
|
|
|