My cursor isn’t changing because my layers failed to be detected when we need to find a layer match.
I have set layerPriority array in the inspector as 4 layers: 0 - default, 9 - walkable, 10 - enemy, 11 - storage. At start, I can see there are 4 layers, but when it comes down to the Find Top Priority Hit method, it can only detect 0, 9.
In Cursor Affordance I hae also set to 9, 10, 11
public class CameraRaycaster_v02 : MonoBehaviour
{
// INSPECTOR PROPERTIES RENDERED BY CUSTOM EDITOR SCRIPT
[SerializeField] int[] layerPriorities;
// More code in between
RaycastHit? FindTopPriorityHit (RaycastHit[] raycastHits)
{
// Form list of layer numbers hit
List<int> layersOfHitColliders = new List<int> ();
foreach (RaycastHit hit in raycastHits)
{
layersOfHitColliders.Add (hit.collider.gameObject.layer);
}
// Step through layers in order of priority looking for a gameobject with that layer
foreach (int layer in layerPriorities)
{
Debug.Log("LAYERPRIORITIES " + layer);
foreach (RaycastHit hit in raycastHits)
{
if (hit.collider.gameObject.layer == layer)
{
return hit; // stop looking
}
}
}
return null; // because cannot use GameObject? nullable
}
}
What can I have done wrong? Would really appreciate any help!