Just finished this lecture and getting this error now.
Looking at the code. I have this in the PlayerCOntroller.cs script
using RPG.Attributes;
using RPG.Combat;
using RPG.Movement;
using UnityEngine;
namespace RPG.Control
{
public class PlayerController : MonoBehaviour
{
Health health;
enum CursorType
{
None,
Movement,
Combat
}
[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 (health.IsDead()) return;
if (InteractWithCombat()) return;
if (InteractWithMovement()) return;
SetCursor(CursorType.None);
}
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);
}
}
}
It says the error is coming from this line at the end of this section
return cursorMapping[0];
private CursorMapping GetCursorMapping(CursorType type)
{
foreach (CursorMapping mapping in cursorMappings)
{
if (mapping.type == type)
{
return mapping;
}
}
return cursorMappings[0];
}
I looked at help for this, but we didn’t assign a “int” for this, so I’m at a bit of a loss.
Anyone have any ideas what went wrong here?
Thank you so much for the help.