Esempio n. 1
0
    public void SpawnCollectiblesAroundObjects(Universe universe)
    {
        List <GameObject> universeObjects = universe.GetUniverseObjects();

        for (int collectibleNum = 0; collectibleNum < NumStartingOfAroundCollectibles; collectibleNum++)
        {
            int        randomElementIndex = Random.Range(0, Collectibles.Count);
            GameObject collectible        = GameObject.Instantiate(Collectibles[randomElementIndex]);

            randomElementIndex = Random.Range(0, universeObjects.Count);
            CellCoordPosition randomObjectPosition = universeObjects[randomElementIndex].GetComponent <CellCoordPosition>();

            CellCoordPosition cellCoordPosition = (CellCoordPosition)collectible.AddComponent(typeof(CellCoordPosition));
            cellCoordPosition.SetCellSize(universe.GetCellSize());

            cellCoordPosition.SetLocalPosition(randomObjectPosition.GetLocalPos().x + Random.Range(0, universe.GetCellSize()),
                                               randomObjectPosition.GetLocalPos().y + Random.Range(0, universe.GetCellSize()),
                                               randomObjectPosition.GetLocalPos().z + Random.Range(0, universe.GetCellSize()));
            cellCoordPosition.SetGlobalPosition((long)randomObjectPosition.GetGlobalPos().x + Random.Range(-1, 1),
                                                (long)randomObjectPosition.GetGlobalPos().y + Random.Range(-1, 1),
                                                (long)randomObjectPosition.GetGlobalPos().z + Random.Range(-1, 1));

            collectible.transform.position = cellCoordPosition.GetRealPosition();

            universe.AddUniverseObject(collectible);
        }
    }
Esempio n. 2
0
    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();
        }
    }
Esempio n. 3
0
    public GameObject InstatntiateUniverseObject(PrefabCoord prefabCoord)
    {
        GameObject universeObject = GameObject.Instantiate(prefabCoord.prefab);

        CellCoordPosition cellCoordPosition = (CellCoordPosition)universeObject.AddComponent(typeof(CellCoordPosition));

        cellCoordPosition.SetCellSize(CellSize);
        cellCoordPosition.SetLocalPosition(prefabCoord.LocalX, prefabCoord.LocalY, prefabCoord.LocalZ);
        cellCoordPosition.SetGlobalPosition(prefabCoord.GlobalX, prefabCoord.GlobalY, prefabCoord.GlobalZ);
        universeObject.transform.position = cellCoordPosition.GetRealPosition();

        universeObjects.Add(universeObject);
        return(universeObject);
    }
Esempio n. 4
0
    public void SpawnStartingCollectibles(Universe universe)
    {
        for (int collectibleNum = 0; collectibleNum < NumStartingOfCollectibles; collectibleNum++)
        {
            int        randomElementIndex = Random.Range(0, Collectibles.Count);
            GameObject collectible        = GameObject.Instantiate(Collectibles[randomElementIndex]);

            CellCoordPosition cellCoordPosition = (CellCoordPosition)collectible.AddComponent(typeof(CellCoordPosition));
            cellCoordPosition.SetCellSize(universe.GetCellSize());
            cellCoordPosition.SetLocalPosition(Random.Range(0, universe.GetCellSize()), Random.Range(0, universe.GetCellSize()), Random.Range(0, universe.GetCellSize()));
            cellCoordPosition.SetGlobalPosition(Random.Range(-SpawnAreaSize, SpawnAreaSize), Random.Range(-SpawnAreaSize, SpawnAreaSize), Random.Range(-SpawnAreaSize, SpawnAreaSize));
            collectible.transform.position = cellCoordPosition.GetRealPosition();

            universe.AddUniverseObject(collectible);
        }
    }
 private void ManageCoordinates()
 {
     transform.Translate(transform.forward * flySpeed, Space.World);
     cellCoordPosition.SetLocalPosition(transform.position.x, transform.position.y, transform.position.z);
 }