- Home /
How can I make weak point's?
public Gameobject shield 1 public Gameobject shield 2 public Gameobject shield 3
//How would I make 3 separate game objects be required to be destroyed first before you can attack a fourth GameObject? If any one of them is still active, you would be unable to deal any damage to the fourth object, even if one of the first three objects is still active.
void OnTriggerEnter(Collider col) { if (shield1 || shield2 || shield3 == false) { curHP -= 15; //will decrease health } else { curHP -= 0; //will not decrease health } }
Answer by Hellium · May 08, 2019 at 05:27 PM
If one of the gameObjects in the array exist and is active, then, the current HP will remain the same. If all the objects have been destroyed (or as disabled), the health will decrease.
public GameObject[] Shields;
void OnTriggerEnter(Collider col)
{
for( int i = 0 ; i < Shields.Length ; ++i )
{
if( Shields[i] != null && Shields[i].activeSelf )
return ;
}
curHP -= 15;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612200954im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to prevent a script on a disabled object from firing? 0 Answers
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
GameObject.setActive(bool) is not activating my gameObject 1 Answer
error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3 Answers
Disabling a script . 1 Answer