Hi all,
For some reason, I’m not getting any matches when checking for the CombatTarget in my hits array. The InteractWithCombat function is getting called fine, and I get 1 or 2 hits back from the initial RaycastAll method - but then when I do the foreach I don’t get any results back.
Any ideas?
namespace RPG.Control
{
public class PlayerController : MonoBehaviour
{
/// OTHER BITS
private void Update()
{
InteractWithCombat();
InteractWithMovement();
}
private void InteractWithCombat()
{
var hits = Physics.RaycastAll(GetMouseRay());
foreach (var hit in hits)
{
var target = hit.transform.GetComponent<CombatTarget>();
if (target == null) continue;
if (Input.GetMouseButtonDown(0)) _fighter.Attack(target);
}
}
/// OTHER BITS
}
using UnityEngine;
namespace RPG.Combat
{
public class CombatTarget : MonoBehaviour
{
}
}
using UnityEngine;
namespace RPG.Combat
{
public class Fighter : MonoBehaviour
{
public void Attack(CombatTarget target)
{
print("I'm attacking...");
}
}
}