Instead of adding the code below to the bullet:
if(otherObject.name == "Boss")
{
Destroy(otherObject.gameObject);
}
You should make a Boss script, or if you already have a Boss script attached to the boss, add this:
// Some Variables
public int hitAmount_Max = 2;
private int hitAmount_Cur;
void OnTriggerEnter(Collider col)
{
// Only take damage from Bullets, because you're a badass
if (col.tag == "Bullet")
{
// Increment the hitAmount
hitAmount_Cur++;
if (hitAmount_Cur >= hitAmount_Max)
{
// You got hit too many times, it's over
Debug.Log("Shit, I'm dead");
Destroy(gameObject);
}
}
}
Make sure not to forget to give the Bullet Prefab a tag named "Bullet" for the above code to work.
Right now your boss is a trigger this way.
If you want the boss to collide with the environment use the following instead:
void OnCollisionEnter(Collision col) {
// Code from above again
}
I hope that helps, if you have any other questions, feel free to ask, if this was all you needed, please accept this answer ;)
Best of luck! :)
↧