Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //get all of the world elements close to the player
        ////world chunks are 10x10 units
        ////divide player location by 10 and floor to get chunk id of player
        ///
        foreach (GroundCreator piece in Pieces)
        {
            piece.gameObject.SetActive(false);
        }

        PlayerChunkLocation = new Vector2(Mathf.Floor(PlayerObject.transform.position.x / 10f), Mathf.Floor(PlayerObject.transform.position.z / 10f));
        for (int x = (int)(PlayerChunkLocation.x - ChunkRenderDistance / 2); x < PlayerChunkLocation.x + ChunkRenderDistance / 2; x++)
        {
            for (int y = (int)(PlayerChunkLocation.y - ChunkRenderDistance / 2); y < PlayerChunkLocation.y + ChunkRenderDistance / 2; y++)
            {
                List <GroundCreator> matches = Pieces.Where(p => p.ChunkX == x && p.ChunkY == y).ToList();
                if (matches.Count > 0)
                {//The piece has already been generated, just show it
                    matches[0].gameObject.SetActive(true);
                }
                else
                {
                    GroundCreator Piece = Instantiate(WorldPiece.gameObject, new Vector3(x * 10, 0, y * 10), Quaternion.identity).GetComponent <GroundCreator>();
                    Piece.ChunkX = x;
                    Piece.ChunkY = y;
                    Pieces.Add(Piece);
                }
            }
        }
    }
Ejemplo n.º 2
0
 // Start is called before the first frame update
 void Awake()
 {
     if (grCreator == null)
     {
         grCreator   = this;
         meshCreator = this.gameObject.GetComponent <MeshCreator>();
         Vector3 swCorner = new Vector3(groundPlane.planeSpecs.minX, 0.0f, groundPlane.planeSpecs.minY);
         meshCreator.CreateGroundMesh(swCorner, resolution, groundPlane.planeSpecs.width * 10.0f, groundPlane.planeSpecs.height * 10.0f); //creates a flat plane but with required resolution
         resoSlider.value = (int)resolution;
         //UpdateTopography();
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
Ejemplo n.º 3
0
 void Awake()
 {
     ground         = GameObject.FindGameObjectWithTag("GameController");
     groundControll = ground.GetComponent <GroundCreator>();
 }
Ejemplo n.º 4
0
 public void InitGame()
 {
     m_GroundCreator = gameObject.transform.Find("GroundCreator").GetComponent <GroundCreator>();
 }
Ejemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     winWidth  = Camera.main.aspect * Camera.main.orthographicSize;
     creator   = GetComponent <GroundCreator> ();
     lvManager = GetComponent <Level> ();
 }