The influence of the subsidiary on the variable parent?
-
I have a gun against which a polygon collider is attached, marking the shelling area. All objects entering the zone are added to the list.
void OnTriggerEnter2D(Collider2D goal) { goalsList.Add(goal.gameObject); }
I've connected to the gun to the subsidiary object Visibility_Area, which has its "review zone" round. Visibility_Area hangs a violin, which adds all the tragger objects to the List.
void OnTriggerEnter2D(Collider2D goal) { visArea.Add(goal.gameObject); }
How do you read this leaf from the parent facility(gun) to check the simultaneous presence in both zones? Or maybe there's another way to pass the information to the object by the gun that some object was in both zones at the same time?
Such questions have already been raised, but none of this has been possible.
Guys, save me! I've broken my head for 24 hours. If you need to add something to the question, I'll need some information.
What has been tested:
Through
childTrans = this.gameObject.transform.GetChild(0); child = childTrans.gameObject; ifGoal = child.ifGoalVis;
I get Visibiliry. But how do you get the list out of him now? If I speak to him now, for example, ifGoal = child.ifGoalVis, where ifGoal is a variable type of bool in the parent, and ifGojectVis is a bool-type argument in the subsidiary, then...ifGoalVis underlines red and says "GameObject" doesn't contain a definition of "ifGoalVis,"Here. https://ru.stackoverflow.com/a/1091986/467156 It's still an interesting way, but I stopped at the very beginning with the creation of UnityEvent. He's just saying the status couldn't find the type or name of the space called UnityEvent. [Assembly-CSharp]ς
Maybe when the facility goes to the subsidiary collider(OnTriggerEnter2D(Collider2D coll), a message can be sent indicating the object to the parent. Something like, "I've got an object coming in with me.gameObject, add it to your List"? And then work with that list in the parent (which would be perfect). Is that possible?
-
It was hard, but I thought:
We work with the target Gun.
Gun is attached to the screenplay Attack:
public class Attack : MonoBehaviour {
public List<GameObject> goalsList; // Список объектов, которые входят в зону атаки
public List<GameObject> visList; // Список объектов, которые видит орудие
public List<GameObject> visGoalList; // Список объектов, которые видны и по которым можно стрелятьvoid Awake() {
goalsList = new List<GameObject>(); // Инициализация списка объектов, которые входят в зону атаки;
visList = new List<GameObject>(); // Инициализация списка объектов, которые видит орудие
visGoalList = new List<GameObject>(); // Инициализация списка объектов, которые видны и по которым можно стрелять
}public virtual void OnTriggerEnter2D(Collider2D goal) {
goalsList.Add(goal.gameObject);
if(visList.Contains(goal.gameObject) == true) {
visGoalList.Add(goal.gameObject);
}
}
public virtual void OnTriggerExit2D(Collider2D goal) {
goalsList.Remove(goal.gameObject);
}// Совершить выстрел (начать обстрел)
void shot() {}
♪
Attack, I started three lists that are filled as objects enter a collider. There is also a function in this class that fills one of the lists(goalsList), but it checks whether there is a facility in Visibility_Area (visList). If so, the third list is filled out.
Visibility_Area attached to visibility_Ar:
public class Visibility_Ar : Attack {
public Attack visArea; / Reference to parentpublic override void OnTriggerEnter2D(Collider2D goal) {
visArea.visList.Add(goal.gameObject);
if(visArea.goalsList.Contains(goal.gameObject) == true) {
visArea.visGoalList.Add(goal.gameObject);
}
}public override void OnTriggerExit2D(Collider2D goal) {
visArea.visList.Remove(goal.gameObject);
}
♪
This class is inherited by Attack class. In it, I make a reference to the parent.
♪ Furthermore, when the object enters the trigher area of Visibility_Area, I add it to the second list (visList) and check whether the facility is on the first list (goalsList) to add it to the third list (visGoalList).
Tadaaama! Now we can check two conditions for shooting at the target in the right sector. Our weapon has detected the target, and the target is in the area of defeat.
If everything looks and works out, it can be modernized, I'd be happy to adjust.