- Home /
An integer that's supposed to get incremented gets reset when a bullet hits.
So I have this enemy ship which is moving at the same speed as the player. The player is behind it and is shooting bullets. Now, there's a trigger on the enemy and a collider on the bullet (both have rigidbodies). The plan is: when a bullet hits the enemy it's health increases until it reaches a certain value and then it gets destroyed. The problem is that when the bullet hits it, the health bar gets incremented and then resets. I don't want it to reset. Any help would be greatly appretiated! Here's the code: public class colliderinstantiator : MonoBehaviour {
public Rigidbody wasp;
public Rigidbody pigeon;
public Rigidbody bullet;
int wasphealth;
public float minDis = 10.0f;
public float drag = 30.0f;
void Start ()
{
wasphealth = 0;
}
void Update ()
{
if (wasp) {
/*if ((wasp.transform.position - bullet.transform.position).sqrMagnitude <= minDis * minDis) {
wasphealth = wasphealth+1;
Debug.Log (wasphealth);
}*/
if (wasp.transform.position.z - pigeon.transform.position.z < 200) {
wasp.velocity = wasp.velocity - wasp.velocity + pigeon.velocity;
}
if (wasphealth >= 30) {
Destroy (GameObject.FindWithTag ("nmy1"));
}
}
}
void OnTriggerEnter (Collider other)
{
Debug.Log (wasphealth);
wasphealth = wasphealth + 1;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612220407im_/https://answers.unity.com/themes/thub/images/avi.jpg)