I am trying to determine what component is being used as a parameter but I have no clue how to try access it as everything throws an error.
This first function AttemptMove detects what the raycast collides with. It then calls the OnCantMove function and uses the T as the parameter.
protected virtual void AttemptMove<T> (int xDir, int yDir) where T: Component
{
RaycastHit2D hit;
bool canMove= Move (xDir, yDir, out hit);
if (hit.transform == null)
return;
T hitComponent = hit.transform.GetComponent<T> ();
//Debug.Log (hit.transform.GetComponent<T> ());
if (!canMove && hitComponent != null)
OnCantMove (hitComponent);
}
protected override void OnCantMove<T>(T component)
{
Wall hitWall = component as Wall;
hitWall.DamageWall (wallDamage);
animator.SetTrigger ("PlayerChop");
}
I want to be able to damage the enemy player the same way I damage the wall so I need to be able to do some sort of check in the OnCantMove function to determine what T is. I am quite unfamiliar with the generic functions in unity so any help will be appreciated.