Hi All,
I have a C# list of colliders (of type List<Collider>
) and I am having a hard time accessing the GetComponent method from the colliders within the list.
Essentially, I assign a collider to the list after a successful raycast.
Ray rayUnit = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hitUnit = new RaycastHit();
int unitLayer = LayerMask.NameToLayer("Unit");
int unitMask = 1 << unitLayer;
if(Physics.Raycast(rayUnit, out hitUnit, Mathf.Infinity, unitMask))
{
hitUnit.collider.GetComponent<Selectable>().selected = true;
selectedUnits.Add(hitUnit.collider);
}
Then later I try to access the collider inside the List:
for(int i=0; i < selectedUnits.Count; i++)
{
selectedUnits*.GetComponent<Selectable>.selected = false;*
- }*
And this fails with the following error:
error CS0119: Expression denotes amethod group', where a
variable’,value' or
type’ was expected
Why can’t I access the GetComponent method?
Thanks in advance for any help.