heya @bixarrio - OK I honestly thought this system was done for, but… the Editing and Destruction systems don’t work. Yes, I do close the UI when I go into either mode, but it doesn’t highlight anything, even if my player can see it. You still have a copy of my project, right? If so, can you please have a look through? I managed to identify the starting part of the problem as follows:
public void SelectDestroyMode()
{
Debug.Log("Destruction Mode Entered");
BuildingPlacer.Instance.ChangeBuildMode(BuildingPlacer.BuildMode.DESTROY);
CloseMenu();
}
This is a function in ‘UICircularBuildingMenu.cs’
The Debugger works, and placing one in ‘BuildingPlacer.Instance.ChangeBuildMode()’ works as well. The problem is… I can no longer highlight the part I want to destroy, and the same problem goes for editing. Can you please have a look at it? It would really mean a lot to me
I asked the developer about this 2 days ago and still no response… (Please help)
All the changes I have done so far were documented. I did not change anything behind the scenes
As soon as you see this message, please let me know
Edit: I figured this out too. I recently had my Terrain’s LayerMask set to “Terrain”, and the system is not programmed to work with that mask. I contacted Andrew about it, but… it’ll probably take some time for him to respond (I asked him how to get the edit and destroy functions to work on different layers too)
Edit 2: With a little bit (OK a lot) of fiddling around, I fixed it. Just let the Raycast camera detect both “Terrain” AND “Default”. Another day, another major problem to encounter
Edit: I developed an algorithm as well which (visibility-wise) hides any construction stuff in your face that might block the view between the player and the camera, something on the fly to ensure that you can see your home. It’s not as smooth as professional games make it seem to be, but for the moment it works. Here’s the algorithm, for anyone who needs it:
using System.Collections.Generic;
using UnityEngine;
public class BuildingVisibilityController : MonoBehaviour
{
public LayerMask buildingLayerMask;
public float visibilityDistanceThreshold = 5f;
public List<Renderer> visibleRenderers = new List<Renderer>();
private void Update()
{
// Iterate over all currently visible renderers and check if they are still visible
for (int i = 0; i < visibleRenderers.Count; i++)
{
Renderer renderer = visibleRenderers[i];
if (renderer != null)
{
float distance = Vector3.Distance(transform.position, renderer.bounds.center);
if (distance >= visibilityDistanceThreshold)
{
renderer.enabled = true; // Set it to be visible again
visibleRenderers.RemoveAt(i); // Remove from the list
i--; // Decrement the index to account for removed item
}
}
}
// Perform a new raycast to find building parts within the visibility threshold
RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward, Mathf.Infinity, buildingLayerMask);
foreach (RaycastHit hit in hits)
{
Renderer renderer = hit.collider.GetComponent<Renderer>();
if (renderer != null && !visibleRenderers.Contains(renderer))
{
float distance = hit.distance;
if (distance < visibilityDistanceThreshold)
{
renderer.enabled = false; // Set it to be invisible
visibleRenderers.Add(renderer); // Add it to the list of visible renderers
}
}
}
}
}
It works by setting the PART of your house as whatever layer you want to hide (for me personally, it’s “Obstacles”), and doing the same for the camera, and then it adds it to a list. Once you’re far enough from that part, it will delete it off the list and re-render it. It could be a little annoying for when you’re coming to the camera and need to see what’s ahead of you, but I haven’t made this a whole lot mature as of yet. For now, Enjoy
if you want to disable the entire gameObject instead (i.e: it doesn’t exist in the game), here’s the script:
using System.Collections.Generic;
using UnityEngine;
// Find a way to deactivate this script when the player is in Construction, Editing, or Destruction Mode
public class BuildingVisibilityController : MonoBehaviour
{
[Header("This script is responsible for hiding any obstacles\nbetween the camera and the player character\n (You still need to find a way to get it to work with Obstacle-Layers, as Construction fails right there)")]
public LayerMask buildingLayerMask;
public float visibilityDistanceThreshold = 5f;
public List<GameObject> visibleObjects = new List<GameObject>();
private void Update()
{
// Iterate over all currently visible objects and check if they are still visible
for (int i = 0; i < visibleObjects.Count; i++)
{
GameObject obj = visibleObjects[i];
if (obj != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance >= visibilityDistanceThreshold)
{
obj.SetActive(true); // Set it to be visible again
visibleObjects.RemoveAt(i); // Remove from the list
i--; // Decrement the index to account for removed item
}
}
}
// Perform a new raycast to find building parts within the visibility threshold
RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward, Mathf.Infinity, buildingLayerMask);
foreach (RaycastHit hit in hits)
{
GameObject obj = hit.collider.gameObject;
if (obj != null && !visibleObjects.Contains(obj))
{
float distance = hit.distance;
if (distance < visibilityDistanceThreshold)
{
obj.SetActive(false); // Set it to be invisible
visibleObjects.Add(obj); // Add it to the list of visible objects
}
}
}
}
}