So I am following a tutorial on creating a simple combat system that is in C# and I am trying to convert it into unity script. I have the scene set up with a simple object that will be the player and three enemies. Each enemy is tagged “Enemy”. I am trying to return their transforms into a List (later I’ll change transform into something else, but I figured it was a good way to get it started). Here is the script Im using on the player object:
import System.Collections.Generic;
public var targets : List.;
public var go : GameObject[];
function Start() {
targets = new List.();
AddAllEnemies();
}
function AddAllEnemies(){
go = GameObject.FindGameObjectsWithTag("Enemy");
for(var enemy : GameObject in go){
AddTarget(enemy.Transform);
}
}
function AddTarget(enemy : Transform){
targets.Add(enemy);
}
So when I go into play mode and inspect my variables, the three enemies are put into the go variable correctly, but when I check the targets variable it is returned with three objects that read None (Transform). Im not sure where Im running into the problem. Any help would be appreciated.
Thanks
edit: the List. both have < Transform > after them. Not sure why it isn’t showing up in the code