Example #1
0
    //! Update tile position of mercenary.
    private void UpdateTilePosition()
    {
        RaycastHit hit;
        Ray        ray = new Ray(new Vector3(transform.position.x, 1, transform.position.z), Vector3.down);

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, Terrain.LAYER_MASK))
        {
            ja2.TerrainPartition.TriangleMap tile_x_y = hit.transform.gameObject.GetComponent <Terrain>().GetTile(hit.triangleIndex);
            mercenary.tile = terrainManager.map.GetTile(tile_x_y.x, tile_x_y.y);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out m_Hit, Mathf.Infinity, Terrain.LAYER_MASK))
        {
            // Find the tile based on triangles
            Terrain terrain = m_Hit.transform.gameObject.GetComponent <Terrain>();
            ja2.TerrainPartition.TriangleMap tile_x_y = terrain.GetTile(m_Hit.triangleIndex);
            tile = map.GetTile(tile_x_y.x, tile_x_y.y);

            Vector3 v0 = ja2.TerrainPartition.TileVertex(tile.x, tile.y, 0);
            Vector3 v1 = ja2.TerrainPartition.TileVertex(tile.x, tile.y, 1);
            transform.position = new Vector3(v1.x, 0, v0.z);
        }
    }