使用Physics.OverlapSphere來檢測不方便調試, 其他都可以.
核心代碼:
//檢測敵人 public void CheckEnemy() { Collider[] cols = Physics.OverlapSphere(this.transform.position, attackRange); if (cols.Length > 0) { foreach (var i in cols) { Debug.Log(i.gameObject.tag); if (i.gameObject.CompareTag("Enemy")) { //檢測到敵人在主角以attackRange半徑的圓里面 } } } }
