public void TestDraw() { DebugTools.DrawDebugBox(_debugPosition, _debugAngle, _debugSize); }
private void ScanForCollision() { Vector2 boxSize = _boxCollider.size; boxSize.x *= _transform.localScale.x; boxSize.y *= _transform.localScale.y; boxSize.y *= 1.0f; boxSize.x *= 2.5f; float angle = this.transform.eulerAngles.z; //Gizmos.DrawWireCube(_transform.position, boxSize); float checkDistance = boxSize.y; //DebugTools.DrawDebugBox(_transform.position, angle, boxSize); DebugTools.DrawDebugBox(_transform.position + _transform.up * checkDistance, angle, boxSize); DebugTools.DrawDebugBox(_transform.position + _transform.up * (checkDistance + _speed * _speedMultiplier), angle, boxSize); RaycastHit2D[] hits = Physics2D.BoxCastAll(_transform.position + _transform.up * checkDistance, boxSize, angle, _transform.up, _speed * _speedMultiplier, _layerMask); if (hits != null && hits.Length > 1) { RaycastHit2D[] newHits = hits.Where <RaycastHit2D>(x => x.collider.gameObject != this.gameObject).ToArray <RaycastHit2D>(); //bool collidingCourse = false; int hitCount = newHits.Length; //for(int i = 0;i < hitCount;++i) //{ // if(hits[i].collider != null && hits[i].collider.gameObject.layer == _layer_obstacle) // { // collidingCourse = true; // break; // } //} if (hitCount > 0) { Vector2 obstaclePosition = newHits[0].collider.transform.position; Vector2 targetPosition = Vector2.Lerp(_transform.position, obstaclePosition, 0.5f); if (_alert == null) { GameObject alertGO = InstanceLord.Instance.GetInstance(InstanceLord.InstanceType.IT_ALERT); if (alertGO != null) { alertGO.SetActive(true); _alert = alertGO.GetComponent <Alert>(); } } if (_alert != null) { _alert.UpdateAlert(targetPosition); } } } else { if (_alert != null) { _alert = null; } } }