How to hide voxels?

Modified on Sat, 04 Jul 2020 at 11:50 AM

Voxels can be hidden using the VoxelSetHidden methods. Use VoxelIsHidden to determine voxel visibility (check API section for full list of public methods).


Hiding voxels is useful when you need the player to see through certain voxel layers or areas. In fact, the see-through system included in Voxel Play makes use internally of these methods.


The code below will hide voxels around player camera when pressing T and returned to normal when pressing Y.

Note that voxels are not removed, they simply are not rendered (colliders and navmesh data is not affected).


using System.Collections.Generic;
using UnityEngine;
using VoxelPlay;


public class HideVoxels : MonoBehaviour
{


    VoxelPlayEnvironment env;
    List<VoxelIndex> indices = new List<VoxelIndex> ();


    void Start()
    {
        env = VoxelPlayEnvironment.instance;
    }


    void Update()
    {
        if (Input.GetKeyDown(KeyCode.T)) {
            Vector3 min = Camera.main.transform.position - new Vector3 (50, 0, 50);
            Vector3 max = Camera.main.transform.position + new Vector3 (50, 20, 50);
            env.GetVoxelIndices (min, max, indices);
            env.VoxelSetHidden (indices, true);
        }
        if (Input.GetKeyDown (KeyCode.Y)) {
            Vector3 min = Camera.main.transform.position - new Vector3 (50, 0, 50);
            Vector3 max = Camera.main.transform.position + new Vector3 (50, 20, 50);
            env.GetVoxelIndices (min, max, indices);
            env.VoxelSetHidden (indices, false);
        }


    }
}




Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article