Hello!
I'm learning now OOP. And I got some questions, about how unity3d works with classes.
First situation:
I'm having a GameObject that has a script:
**Bot Script:**
public class Bot : MonoBehaviour
{
void Start ()
{
....EnemysList.Add(new Enemy(this.gameObject, 100));
}
}
====================
Where Enemy class is this:
public class Enemy : Enemys
{
public int EnemysCount;
private int Health;
private GameObject Owner;
public Enemy(GameObject WhoCreated,int newHealth)
{
EnemysCount++;
Owner = WhoCreated;
Health = Health;
}
public int Master
{
get
{
//Returning class owner
return Owner;
}
}
}
And Enemy is a part of Enemys class, that stores in a list all new Enemy classes ( **EnemysList**):
**So First question is:**
If I want to know who is owner of class from EnemysList(that stores all classes that were created by Bot on Start()), is there better way to access GameObject, than Enemys.EnemysList[0].Master? I mean, that should I really add to class GameObject variable? Or there is another way of doing it?
**Second question is:**
If my GameObject with Bot script, will be removed, do I need to remove from list that class? Or Unity3d does it by itself? And if I need, how can I remove class from list Enemys.EnemysList[n]?
↧