void Start() { universe = (Universe)GameObject.Find("GameManager").GetComponent(typeof(Universe)); cellCoordPosition = gameObject.GetComponent <CellCoordPosition>(); shadowManager = gameObject.GetComponent <ShadowManager>(); for (int i = 0; i < numOfPlanets; i++) { int randomIndex = Random.Range(0, planets.Count); GameObject planet = planets[randomIndex]; PrefabCoord planetCoord = new PrefabCoord(); planetCoord.prefab = planet; planetCoord.GlobalX = (long)Random.Range(-maxGlobalDistance, maxGlobalDistance); planetCoord.GlobalY = (long)Random.Range(-maxGlobalDistance, maxGlobalDistance); planetCoord.GlobalZ = 0; planetCoord.LocalX = Random.Range(-cellCoordPosition.GetCellSize(), cellCoordPosition.GetCellSize()); planetCoord.LocalY = Random.Range(-cellCoordPosition.GetCellSize(), cellCoordPosition.GetCellSize()); planetCoord.LocalZ = 0; planetCoord.GlobalX += (long)cellCoordPosition.GetGlobalPos().x; planetCoord.GlobalY += (long)cellCoordPosition.GetGlobalPos().y; planetCoord.GlobalZ += (long)cellCoordPosition.GetGlobalPos().z; planetCoord.LocalX += cellCoordPosition.GetLocalPos().x; planetCoord.LocalY += cellCoordPosition.GetLocalPos().y; planetCoord.LocalZ += cellCoordPosition.GetLocalPos().z; GameObject instantiatedPlanet = universe.InstatntiateUniverseObject(planetCoord); instantiatedPlanets.Add(instantiatedPlanet); shadowManager.planet[i] = instantiatedPlanet; } shadowManager.Init(numOfPlanets); }
void Start() { playerPosition = (CellCoordPosition)GameObject.Find("Player").GetComponent(typeof(CellCoordPosition)); lodObjectPosition = (CellCoordPosition)gameObject.GetComponent(typeof(CellCoordPosition)); foreach (PrefabDistance prefabDistance in prefabDistances) { prefabDistance.CalculateMaxDistance(lodObjectPosition.GetCellSize()); prefabDistance.CalculateMinDistance(lodObjectPosition.GetCellSize()); } }
void Update() { foreach (PrefabDistance prefabDistance in prefabDistances) { double distance = CellCoordUtils.Distance(playerPosition, lodObjectPosition, lodObjectPosition.GetCellSize()); if (distance > prefabDistance.GetMinDistance() && distance < prefabDistance.GetMaxDistance()) { if (distance < prevMinDistance || distance > prevMaxDistance) { prevMinDistance = prefabDistance.GetMinDistance(); prevMaxDistance = prefabDistance.GetMaxDistance(); GameObject.Destroy(currentObject); currentObject = GameObject.Instantiate(prefabDistance.prefab); currentObject.transform.parent = gameObject.transform; currentObject.transform.position = gameObject.transform.position; } } } }
void Update() { Vector3 localCoordDiff = (cellCoordPosition.GetGlobalPos() - playerPosition.GetGlobalPos()) * cellCoordPosition.GetCellSize(); Vector3 localPosition = new Vector3(transform.position.x - localCoordDiff.x, transform.position.y - localCoordDiff.y, transform.position.z - localCoordDiff.z); cellCoordPosition.SetLocalPosition(localPosition.x, localPosition.y, localPosition.z); if (cellCoordPosition.OutOfCell()) { cellCoordPosition.UpdateGlobalPos(); cellCoordPosition.SnapCoordsBackToCell(); } }