public void Stop() { StopAllCoroutines(); if (!keepcolor) { if (channelmode) { try { pulseTrigger = pulseParent.getActiveTrigger(channel_id).GetComponent <PulseTrigger>(); } catch { pulseTrigger = null; } activePulseTrigger = pulseTrigger != null && !pulseTrigger.getFinished(); if (!activePulseTrigger) { channel.Set(new_color); } else { pulseTrigger.setOldColor(new_color); } //channel.Set(new_color); } else { foreach (GameObject obj in objects) { if (obj.GetComponent <SpriteRenderer>() != null) { SpriteRenderer renderer = obj.GetComponent <SpriteRenderer>(); renderer.color = new_color; } else if (obj.GetComponent <Tilemap>() != null) { Tilemap renderer = obj.GetComponent <Tilemap>(); renderer.color = new_color; } else if (obj.GetComponent <Light2D>() != null) { Light2D renderer = obj.GetComponent <Light2D>(); renderer.color = new_color; } else if (obj.GetComponent <Graphic>() != null) { Graphic renderer = obj.GetComponent <Graphic>(); renderer.color = new_color; } } } } inuse = false; if (oneuse) { Destroy(gameObject); } }
private IEnumerator ChangeColor(int index) { float time = 0; Color curr = curr_color[index]; GameObject obj = new GameObject(); if (!channelmode) { obj = objects[index]; } if (duration > 0) { while (curr != new_color) { //curr_color = Color.Lerp(curr_color, new_color, Mathf.PingPong(Time.time, 1/duration)); curr = Color.Lerp(curr, new_color, time); if (channelmode) { try { pulseTrigger = pulseParent.getActiveTrigger(channel_id).GetComponent <PulseTrigger>(); } catch { pulseTrigger = null; } activePulseTrigger = pulseTrigger != null && !pulseTrigger.getFinished(); if (!activePulseTrigger) { channel.Set(curr); } else { pulseTrigger.setOldColor(curr); } } else { if (obj.GetComponent <SpriteRenderer>() != null) { SpriteRenderer renderer = obj.GetComponent <SpriteRenderer>(); renderer.color = curr; } else if (obj.GetComponent <Tilemap>() != null) { Tilemap renderer = obj.GetComponent <Tilemap>(); renderer.color = curr; } else if (obj.GetComponent <Light2D>() != null) { Light2D renderer = obj.GetComponent <Light2D>(); renderer.color = curr; } else if (obj.GetComponent <Graphic>() != null) { Graphic renderer = obj.GetComponent <Graphic>(); renderer.color = curr; } } time += Time.deltaTime / (duration * 100); yield return(null); } } if (channelmode) { try { pulseTrigger = pulseParent.getActiveTrigger(channel_id).GetComponent <PulseTrigger>(); } catch { pulseTrigger = null; } activePulseTrigger = pulseTrigger != null && !pulseTrigger.getFinished(); if (!activePulseTrigger) { channel.Set(new_color); } else { pulseTrigger.setOldColor(new_color); } } else { if (obj.GetComponent <SpriteRenderer>() != null) { SpriteRenderer renderer = obj.GetComponent <SpriteRenderer>(); renderer.color = new_color; } else if (obj.GetComponent <Tilemap>() != null) { Tilemap renderer = obj.GetComponent <Tilemap>(); renderer.color = new_color; } else if (obj.GetComponent <Light2D>() != null) { Light2D renderer = obj.GetComponent <Light2D>(); renderer.color = new_color; } else if (obj.GetComponent <Graphic>() != null) { Graphic renderer = obj.GetComponent <Graphic>(); renderer.color = new_color; } } //Debug.Log("COLOR: " + (channel.channelcolor == new_color)); if (oneuse) { Destroy(gameObject); } inuse = false; }