/// <summary> /// Apply random position to a game object within the specified radius. /// </summary> /// <param name="Instance">Game object instance to randomise the position of within a sphere.</param> public void Apply(ref GameObject Instance) { if (Radius > 0f) // randomise position within a radius enabled? { // normal spawn within a sphere if (!ForceOnNAVMesh) { UnityEngine.Random.InitState(System.Environment.TickCount); // reseed Vector3 v3NewPosition = Instance.transform.position + (UnityEngine.Random.insideUnitSphere * Radius); // alter the position if (!IncludeX) // don't include the X plane { v3NewPosition.x = Instance.transform.position.x; // reset } if (!IncludeY) // don't include the Y plane { v3NewPosition.y = Instance.transform.position.y; // reset } if (!IncludeZ) // don't include the Z plane { v3NewPosition.z = Instance.transform.position.z; // reset } Instance.transform.position = v3NewPosition; // update the transform } else // NAV mesh variant { Instance.transform.position = GlobalFuncs.RandomNavSphere(Instance.transform.position, Radius); } } }