I have an array of GameObjects and I wanna get them with "FindGameObjectsWithTag" method.In my BaseEnemy class on start I change tag to "Enemy" and in result I get only one GameObject(instead of 3)
public class BaseEnemy : MonoBehaviour
{
protected float max_speed;
[SerializeField]
protected float speed;
protected float max_hp;
[SerializeField]
protected float hp;
protected float max_damage;
[SerializeField]
protected float damage;
protected Rigidbody2D rb;
protected Controller controller;
public GameObject enemy;
private void Start ()
{
enemy.tag = "Enemy";
controller = GameController.FindObjectOfType ();
rb = GetComponent ();
hp = max_hp;
speed = max_speed;
damage = max_speed;
}
}
public class GameController: MonoBehaviour
{
public GameObject[] enemies;
private void Start ()
{
enemies = GameObject.FindGameObjectsWithTag("Enemy");
}
}
↧