It keeps returning heaps of Null Reference Exceptions and I don’t understand why
public bool Interact_Combat()
{
RaycastHit[] All_Ray_Hits= Physics.RaycastAll(GetMouseRay());
foreach(RaycastHit HitVar in All_Ray_Hits)
{
Combat_Target Hit_Target = HitVar.transform.GetComponent<Combat_Target>();
if(Hit_Target==null)
{
continue;
}
if(!GetComponent<Fighter>().Can_Attack(Hit_Target.gameObject)){ continue;}
if (Input.GetMouseButtonDown(0))
{
GetComponent<Fighter>().Attack_Target(Hit_Target);
}
return true;
}
return false;
}
public bool Can_Attack(GameObject AttackTarget)
{if (AttackTarget == null) { return false; }
Health TestTarget = AttackTarget.GetComponent<Health>();
return TestTarget != null && !TestTarget.IsReallyDead();
}
NullReferenceException: Object reference not set to an instance of an object
RPG.Control.Player_Controller.Interact_Combat () (at Assets/Script/Controller/Player_Controller.cs:36)
RPG.Control.Player_Controller.Update () (at Assets/Script/Controller/Player_Controller.cs:23)