Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The object script must contain some kind of public variable in_zone, which is false by default. Also, the object must be recognized somehow, for example, by a tag, but you can come up with many other ways. For example, the script for an object is called object_script. Then in the zone script:
List<GameObject> objects;
void OnTriggerEnter(Collider other)
{
if(other.tag == "object") //Можно выбрать любой тэг
{
if(!other.GetComponent<object_skript>().in_zone) // проверка не в зоне ли уже объект
{
other.GetComponent<object_skript>().in_zone = true; // объект попал в зону
objects.Add(new GameObject());
objects[objects.Count - 1] = other.gameObject; // Добавление в лист нового компонента
}
}
}
bool x = true;
for(int i = 0; i < objects.Count;)
{
if(objects[i] == null)
{
x = false;
objects[i] = other.gameObject;
other.GetComponent<object_skript>().in_zone = true;
break;
}
++i;
}
if(x)
{
other.GetComponent<object_skript>().in_zone = true;
objects.Add(new GameObject());
objects[objects.Count - 1] = other.gameObject;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question