- Home /
Question by
Chase1 · May 07, 2019 at 03:52 PM ·
ontriggerentershieldhealth-deduction
How can I make it so a bullet wont hurt a weakpoit until these object are disabled?
public GameObject shield1; public GameObject shield2; public GameObject shield3;
void OnTriggerEnter(Collider col)
{
if (shield1 || shield2 || shield3 == false)
{
curHP -= 15; //will decrease health
}
else
{
curHP -= 0; //will not decrease health
}
}
Comment
Answer by Magso · May 07, 2019 at 04:33 PM
Only disable the mesh renderer on the shields and check them with variables or array.
public bool[] shield;
shield[0] = shield1.GetComponent().enabled;
//etc
void OnTriggerEnter(Collider col)
{
if (!shield[0] || !shield[1] || !shield[2])
{
curHP -= 15; //will decrease health
}
}
That was bad, I made a mistake and copied
if (!shield1 || !shield2 || !shield3)
:/
Your answer
![](https://koobas.hobune.stream/wayback/20220612200907im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What is wrong with my HealthBar/Damage Script? 2 Answers
Can I instantiate a collision with a plane? 2 Answers
OnTriggerEnter not working 0 Answers
Making an Object Move on Trigger Enter 1 Answer
InvokeRepeating repeating too often with OnTriggerEnter 1 Answer