// ------------------------------------------------------------------ void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Enemy") { AIEnemy pAI = other.gameObject.GetComponent <AIEnemy>(); if (pAI && (ENUM_ModeMonster)pAI.DBFData.Mode == ENUM_ModeMonster.NoMove) { ObjObstacle = other.gameObject; if (SysMain.pthis.AtkEnemy.ContainsKey(other.gameObject) == false) { SysMain.pthis.AtkEnemy.Add(other.gameObject, pAI.GetTheat()); } } } }
// ------------------------------------------------------------------ // 取得目標. void GetTarget() { // 沒有可作為目標的怪物. if (SysMain.pthis.AtkEnemy.Count == 0) { ObjTarget = null; fRectCount = Time.time + fRectTime; } foreach (KeyValuePair <GameObject, int> itor in SysMain.pthis.AtkEnemy) { // 確認現在是否有目標. if (ObjTarget == null) { ObjTarget = itor.Key; return; } AIEnemy pTargetAI = ObjTarget.GetComponent <AIEnemy>(); AIEnemy pObjAi = itor.Key.GetComponent <AIEnemy>(); // 比較威脅值. if (pTargetAI.GetTheat() < pObjAi.GetTheat()) { ObjTarget = itor.Key; return; } float fDisTarget = Vector2.Distance(transform.position, ObjTarget.transform.position); float fDisObj = Vector2.Distance(transform.position, itor.Key.transform.position); // 比較距離. if (fDisTarget > fDisObj) { ObjTarget = itor.Key; } } }