using System.Collections; using System.Collections.Generic; using UnityEngine; public class Early_Warning : MonoBehaviour { /// /// 必然发生标志位 /// bool Certain_Occur =true; /// /// 随机发生 /// bool isTrigger = true ; // Start is called before the first frame update private void OnTriggerEnter(Collider other) { if (other.name == "ColliderBody") { Random_Occur(); print("ISTRIGGER" + isTrigger); if (!isTrigger) return; //下面执行交叉预警功能 transform.GetChild(0).gameObject.SetActive(true); } } private void Random_Occur() { if (Certain_Occur) { Certain_Occur = false; return; } isTrigger = Random.Range(0, 3) > 1 ? true : false;//随机0.1,2,大与1触发 } }