I updated the link for github in the original post, I also included a video that demonstrates the issues. note that the cursor does not change where there is no navmesh, and that the cursor doesn’t change to “none” until the character is out on the docks and you can see the edge of the terrain through the water. this makes me think its an editor setting and not a code issue.
my playercontroller.cs this is one video ahead of where I noted the issue beginning.
using RPG.Combat;
using RPG.Movement;
using UnityEngine;
using RPG.Attributes;
using System;
using UnityEngine.EventSystems;
namespace RPG.Control
{
public class PlayerController : MonoBehaviour
{
Health health;
enum CursorType
{
None,
Movement,
Combat,
UI,
}
[System.Serializable]
struct CursorMapping
{
public CursorType type;
public Texture2D texture;
public Vector2 hotspot;
}
[SerializeField] CursorMapping[] cursorMappings = null;
private void Awake()
{
health = GetComponent<Health>();
}
private void Update()
{
if (InteractWithUI()) return;
if (health.IsDead())
{
SetCursor(CursorType.None);
return;
}
if (InteractWithCombat()) return;
if (InteractWithMovement()) return;
SetCursor(CursorType.None);
}
private bool InteractWithUI()
{
if (EventSystem.current.IsPointerOverGameObject())
{
SetCursor(CursorType.UI);
return true;
}
return false;
}
private bool InteractWithCombat()
{
RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
foreach (RaycastHit hit in hits)
{
CombatTarget target = hit.transform.GetComponent<CombatTarget>();
if (target == null) continue;
if (!GetComponent<Fighter>().CanAttack(target.gameObject))
{
continue;
}
if (Input.GetMouseButton(0))
{
GetComponent<Fighter>().Attack(target.gameObject);
}
SetCursor(CursorType.Combat);
return true;
}
return false;
}
private bool InteractWithMovement()
{
RaycastHit hit;
bool hasHit = Physics.Raycast(GetMouseRay(), out hit);
if (hasHit)
{
if (Input.GetMouseButton(0))
{
GetComponent<Mover>().StartMoveAction(hit.point, 1f);
}
SetCursor(CursorType.Movement);
return true;
}
return false;
}
private void SetCursor(CursorType type)
{
CursorMapping mapping = GetCursorMapping(type);
Cursor.SetCursor(mapping.texture, mapping.hotspot, CursorMode.Auto);
}
private CursorMapping GetCursorMapping(CursorType type)
{
foreach (CursorMapping mapping in cursorMappings)
{
if (mapping.type == type)
{
return mapping;
}
}
return cursorMappings[0];
}
private static Ray GetMouseRay()
{
return Camera.main.ScreenPointToRay(Input.mousePosition);
}
}
}