I’m trying to iterate through all stored gameObject in a List and if a certain condition is met (in this case, if the gameObject is seen by the player), access another list in the current gameObject and add to it:
var List1 : new List.<GameObject>(); //contains all Characters in scene
var SeenBy : new List.<GameObject>();
for (var CurrentObject : GameObject in List1)
{
CurrentObject.GetComponent(LineOfSight).SeenBy.Add(gameObject); //access the other objects SeenBy List and add this gameObject to it
}
However, I get this error:
Assets/Scripts/LineOfSight.js(7,46): BCE0023: No appropriate version of ‘UnityEngine.GameObject.GetComponent’ for the argument list ‘(function(UnityEngine.GameObject): boolean)’ was found.
What am I doing wrong? How do I access Lists or even normal variables (tried that too via GetComponent) while iterating through a List?