I'm making a 2d tower defense game and getting weird behavior with the bullets, but **only** when it runs in WebGL
Basically, my towers instantiate bullets and transform their position toward the enemy:
void Update() { if (set == true) { //move bullet to target position float timeInterval = Time.time - startTime; gameObject.transform.position = Vector3.Lerp(startPosition, targetPosition, timeInterval * speed / distance); //apply damage on hit if (gameObject.transform.position.Equals(targetPosition)) { if (target != null) { int randomCrit = Random.Range(0, 100); // choose random # between 0 and 99 if (randomCrit < critChance) { target.GetComponent().criticalHit(); // critical hit
target.GetComponent().currentHP -= damage * critMultiplier;
}
else
target.GetComponent().currentHP -= damage; //normal damage
target.GetComponent().lastHitFrom = towerThatCreatedBullet;
}
Destroy(gameObject);
}
}
}
It works great in the Unity Editor.
The weird thing is, when it runs in WebGL, sometimes, but not all the time (seemingly random, say about 50% of the time) the bullet reaches the target, but applies no damage, and then it just sits there in place and Destroy(gameobject) never runs.
So I'm thinking this statement: if (gameObject.transform.position.Equals(targetPosition)) never equates to True, but only in WebGL.
Does anyone have any thoughts on why this might be happening?
Thanks in advance!!
Basically, my towers instantiate bullets and transform their position toward the enemy:
void Update() { if (set == true) { //move bullet to target position float timeInterval = Time.time - startTime; gameObject.transform.position = Vector3.Lerp(startPosition, targetPosition, timeInterval * speed / distance); //apply damage on hit if (gameObject.transform.position.Equals(targetPosition)) { if (target != null) { int randomCrit = Random.Range(0, 100); // choose random # between 0 and 99 if (randomCrit < critChance) { target.GetComponent
It works great in the Unity Editor.
The weird thing is, when it runs in WebGL, sometimes, but not all the time (seemingly random, say about 50% of the time) the bullet reaches the target, but applies no damage, and then it just sits there in place and Destroy(gameobject) never runs.
So I'm thinking this statement: if (gameObject.transform.position.Equals(targetPosition)) never equates to True, but only in WebGL.
Does anyone have any thoughts on why this might be happening?
Thanks in advance!!