bool CheckSetAvailablePos() { if (!NeedToActivate || FixPos) //fixed spawn { return(true); } RaycastHit[] hitInfos = SceneMan.DependenceHitTst(this); if (hitInfos != null && hitInfos.Length > 0) { if (hitInfos.Length > 1) { PeEntity mainPlayer = PeCreature.Instance.mainPlayer; if (null != mainPlayer) { float[] dHeight = new float[hitInfos.Length]; float totalDHeight = 0; int hitIndex = -1; for (int i = 0; i < hitInfos.Length; ++i) { dHeight[i] = Mathf.Abs(hitInfos [i].point.y - mainPlayer.position.y); if (dHeight[i] > PETools.PEMath.Epsilon) { dHeight[i] = 1f / dHeight[i]; totalDHeight += dHeight[i]; } else { hitIndex = i; break; } } if (hitIndex < 0) { float randomValue = UnityEngine.Random.Range(0, totalDHeight); float countDHeight = 0; for (int i = 0; i < dHeight.Length; ++i) { if (randomValue < dHeight[i] + countDHeight) { hitIndex = i; break; } countDHeight += dHeight[i]; } } _pos.y = hitInfos [hitIndex].point.y + 1; dHeight = null; } else { _pos.y = Mathf.Max(hitInfos [0].point.y, hitInfos [1].point.y) + 1; } } else { _pos.y = hitInfos [0].point.y + 1; } return(true); } return(false); }