using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class lightFlash : MonoBehaviour { // Start is called before the first frame update public Material[] materials; public Color[] colors; public Image image; public Color[] banzis; public Color lastColor,aimColor; public float time; public PanDuan panDuan; public float jstime; public Color blue; public GameObject jieshu,jieshu2; void Start() { colors = new Color[materials.Length]; for (int i = 0; i < colors.Length; i++) { colors[i] = materials[i].color; } panDuan.SetOne(true); } // Update is called once per frame void Update() { for (int i = 0; i < colors.Length; i++) { float a = (Mathf.Sin(Time.time * 20)+1)*0.5f; materials[i].color = new Color(colors[i].r, colors[i].g, colors[i].b, a); } time += Time.deltaTime; if (time > 0.2f) { time = 0; lastColor = image.color; aimColor = banzis[Random.Range(0, banzis.Length)]; } image.color = Color.Lerp(lastColor, aimColor, time * 6); jstime += Time.deltaTime; if (jstime>=6) { gameObject.SetActive(false); } } private void OnDisable() { for (int i = 0; i < colors.Length; i++) { materials[i].color = new Color(colors[i].r, colors[i].g, colors[i].b, 1); image.color = blue; jieshu.SetActive(true); jieshu2.SetActive(true); } } }